Use Formatted Text field as plain text

16 views
Skip to first unread message

Elizabeth R.

unread,
Nov 15, 2016, 3:44:41 PM11/15/16
to Hippo Community
We are using Hippo 10.x with Freemarker templates for the front end

We have a Doc Type with a Formatted Text field (let's call it Title). We display that field on the page without any problem with the limited formatting allowed by a Formatted Text field (using the hst.html tag).

I'd like to also use that same content minus the formatting as part of the <title> tag on the page. Is there a way (either directly in the FTL or in the Java back end for the component) to get a copy of the content from that Formatted Text field but as plain text, i.e. with all the HTML tags stripped out?

This seems like something a lot of systems would have reason to do, but I haven't been able to find an appropriate example or reference.

Thanks
-Elizabeth

Woonsan Ko

unread,
Nov 15, 2016, 3:56:37 PM11/15/16
to hippo-c...@googlegroups.com
On Tue, Nov 15, 2016 at 9:44 PM, Elizabeth R. <ereid...@gmail.com> wrote:
We are using Hippo 10.x with Freemarker templates for the front end

We have a Doc Type with a Formatted Text field (let's call it Title). We display that field on the page without any problem with the limited formatting allowed by a Formatted Text field (using the hst.html tag).

I'd like to also use that same content minus the formatting as part of the <title> tag on the page. Is there a way (either directly in the FTL or in the Java back end for the component) to get a copy of the content from that Formatted Text field but as plain text, i.e. with all the HTML tags stripped out?
You can use this static utility method:
- org.hippoecm.hst.utils.SimpleHtmlExtractor#getText(String html)
 

This seems like something a lot of systems would have reason to do, but I haven't been able to find an appropriate example or reference.
The utility was documented for a different use case:

Regards,

Woonsan
 

Thanks
-Elizabeth

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466

NotAHippoTamer

unread,
Nov 16, 2016, 5:20:47 AM11/16/16
to Hippo Community
Hi,

I have already come across the static method org.hippoecm.hst.utils.SimpleHtmlExtractor.getText(String html) but I didn't succeed in call in it directly in the FTL, so the other solution was to use a regex to remove the html tags from the content :
${bean.content.content?replace('<[^>]+/>','', 'r')}

Best regards
Reply all
Reply to author
Forward
0 new messages