I've got an internationalised app that uses spring and freemarker. I'm getting content from localised property files using.
${rc.getMessage("help.headings.frequently_asked_questions")}
For some of the content there are carriage returns in the property values. Because I'm displaying in a web page I'd like to replace these with
.
What is the best way to do this?
Edit: looking closer it seems that I don't actually have carriage returns in the property files. The properties are coming back as single line strings.
Is there a better way to declare the properties so they know they are multi-line?
help.faq.answer.new_users=If you have not yet set a PIN, please enter your username and passcode (from your token) in the boxes provided and leave the PIN field blank.\
You will be taken through the steps to create a PIN the first time you log in.
Cheers, Pete
s = s. replaceAll("\\n", ""); s = s. replaceAll("\\r", "");
esc creates a markup output value out of a string value by escaping all special characters in it.
For example, if you create a variable called "foo" in the template, you can print its value with ${foo} . If, coincidently, there's a variable called "foo" in the data-model too, the variable created in the template will hide (not overwrite!)
${springMacroRequestContext.getMessage("help.headings.frequently_asked_questions", [], "", false)?html?replace("\n", "<br>")}
To handle CR + LF (carriage return + line feed) line endings, as well as just LF do this:
<#escape x as x?html?replace("\\r?\\n","<br />",'r')>...</#escape>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With