Assuming the following string template, is being given a list of Java Bean objects:
<ul>$people:{p|<li>$p.name$ $p.email</li>}$</ul>
ie the list of people might contain Person
objects which you may or may not have the ability to enhance/extend:
class Person {
....
public getName() { ... }
public getEmail() { ... }
}
The getName()
and getEmail()
methods don't return sanitised (escaped html entities). How do you get around this?
You may use a custom renderer, for example:
Then in the template indicate you want it escaped:
That said, you may prefer to scrub the data on input, convert before sending to the template, send a decorated person to the template, etc.
This outputs:
It's not necessary to write your own renderer for this. You may use the builtin renderer org.stringtemplate.v4.StringRenderer
and add in your template :