Is there a built-in in Freemarker that allows me to entirely remove HTML tags from a string?

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’)}

Leave a comment

Your email address will not be published. Required fields are marked *