Forcing FreeMarker to render HTML markup

Prepared data input to FreeMarker templates is assumed to be free of any HTML tags. Any HTML markup tags embedded within prepared data will be ignored, and the data will be rendered as is.

There are cases where prepared data contains HTML markup that you want FreeMarker to render as markup. For example, you may have content stored within the database that has HTML markup tags included. In this scenario, you will need to force FreeMarker to read HTML as markup and render accordingly.

How to do it...

Within the FreeMarker template file, wrap the prepared data in the following OFBiz provided utility:

${StringUtil.wrapString(textData)}

How it works

FreeMarker is a templating engine that merges prepared data with FreeMarker templating instructions to output HTML (and other) document type(s). The data that is fed into a FreeMarker template is assumed to be free of any HTML tags as the template itself typically contains all the HTML markup necessary to render the final document.

When data containing HTML markup is passed as prepared data to a FreeMarker template, any embedded HTML tags are rendered as character equivalents and not HTML markup. For example, if prepared data contains the character sequence<p> then the final HTML document will display the character sequence<p>. That's fine if you want<p> displayed. But what if you really want<p> to be HTML markup for the beginning of a paragraph?

To force the FreeMarker engine to view prepared data with an eye towards using embedded HTML markup as HTML markup, you will need to wrap the prepared data as shown earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.189.23