java - How to pass String as input in FreeMarker? -


this question has answer here:

all templates stored in database. , have fetch contents of template database , marked freemarker. end output rendered in textbox.

but, not finding methodology can send string instead of file name.

please suggest.

you can pass template template constructor stringreader:

  // template string 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(); 

Comments