All the templates are stored in database. And i have to fetch contents of a template from database and marked up with freemarker. The end output will be rendered in a textbox.
But, i am not finding any methodology by which i can send string instead of file name.
Please suggest.
$( document ). ready(function() { var html = ${itemsToAppendTo} $('. gTA'). append( html ) });
Interpolation and concatenation. If you want to insert the value of an expression into a string, you can use ${...} (and the deprecated #{...} ) in string literals. ${...} in string literals behaves similarly as in text sections (so it goes through the same locale sensitive number and date/time formatting).
In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.
c (when used with numerical value) This built-in converts a number to string for a "computer language" as opposed to for human audience. That is, it formats with the rules that programming languages used to use, which is independent of all the locale and number format settings of FreeMarker.
You can pass your template to the Template constructor with a StringReader:
// Get your template as a String from the DB
String template = getTemplateFromDatabase();
Map<String, Object> model = getModel();
Configuration cfg = new Configuration();
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template t = new Template("templateName", new StringReader(template), cfg);
Writer out = new StringWriter();
t.process(model, out);
String transformedTemplate = out.toString();
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