Map<String, String> model = new HashMap<String, String>();
model.put("A", "1");
model.put("b", "2");
model.put("c", "3");
try{
content.append(FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate(ftlName), model));
...
and Ftl file looks like this :
<html><head></head><body>
${model["A"]}
<#list model?keys as prop>
${model[prop]}
</#list>
</body>
</html>
Hwoever I am getting the error :
Expression model is undefined on line 6, column 3 in vslEmail.ftl.
The problematic instruction:
----------
==> ${model["A"]} [on line 6, column 1 in vslEmail.ftl]
----------
Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression model is undefined on line 6, column 3 in vslEmail.ftl.
I get the same error if I remove try to access model using only the list directive … any help appreciated
In case anyone else is stupidly perplexed like I was you have to do this in FTL :
or make A a hashmap instead of a string and loop through that, not the “top” model object.