I need to pass a Map<String,String> into a Freemarker template, and then, inside the template, cherry pick which values I pluck from the injected map. So something like:
// This map will have a 'fizz' key with a String value of 'buzz'.
Map<String,String> mymap = getSomehow();
Configuration cfg = new Configuration();
Template template = cfg.getTemplate("mytempl.ftl");
StringWriter sw = new StringWriter();
template.process(mymap, sw);
And then, the template (mytempl.ftl):
<h1>${mymap[fizz]}</h1>
But when I run this, I get:
FreeMarker template error: The following has evaluated to null or missing: ==> mymap
Any ideas where I'm going awry?
The first parameter to the process Method is the "context" of the Template. So to pick specific values from the Map you can just use <h1>${fizz}</h1>.
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