Skip to content Skip to sidebar Skip to footer

Remove Html Tags In Freemarker Template

I've got a freemarker template that displays the same string in a context where HTML is allowed as well as a context where it is not. Is there a built-in in Freemarker that allows

Solution 1:

You could use the Freemarker built-in string replace function with the "r" flag to enable regular expressions.

Here's a simple regexp that does the trick:

${page_title?replace('<[^>]+>','','r')}

Note that if you use backslashes within the regular expression they must be escaped, as follows (contrived example that removes whitespace):

${page_title?replace('\\s+','','r')}

Solution 2:

There isn't anything built in as of 2.3.28, so yes, you have to create your own.

Post a Comment for "Remove Html Tags In Freemarker Template"