Reputation: 127
I need to bind couple of strings and few html snippets. Output HTML should contain data along with HTML(in design).
Upvotes: 0
Views: 222
Reputation: 31162
Let's say your data-model is a Map<String, Object>
, called model
(could be bean with getters too of course). Then you should fill the mode like this:
model.put("htmlSnippet", HTMLOutputFormat.INSTANCE.fromMarkup("This is <em>HTML</em>!");
model.put("plainTextSnippet", "This is <em>not</em> HTML!");
Above, htmlSnippet
will be a TemplateHTMLOutputModel
object, not a String
, so FreeMarker will know that it mustn't be HTML-escaped.
Now if your template is this, and you have HTML auto-escaping enabled (typically done by giving ftlh
file extension, or with <#ftl outputFormat='HTML'>
header, or otherwise in the Configuration
):
${htmlSnippet}
${plainTextSnippet}
Then the HTML source of the output will be this:
This is <em>HTML</em>!
This is <em>not</em> HTML!
Upvotes: 1