springfreemarker

How do I replace carriage returns with <br /> using freemarker and spring?


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


Solution

  • ${springMacroRequestContext.getMessage("help.headings.frequently_asked_questions", [], "", false)?html?replace("\n", "<br>")}