We have a scenario like the input data of Freemarker expression contains spaces in variable ${employee name?} and getting below error
"Exception in thread "main" freemarker.core.ParseException: Encountered "name" at line 1, column 12 in EMAILTEMPLATES
" while applying the expression .
Does Freemarker support space in free marker variable?
Map<Object,Object> out= new HashMap<>();
out.put("employee name", "XXX");
String templateStr="<p> ${employee name?} </p>";
StringWriter out = new StringWriter();
Template emailTemplate = new Template(EMAILTEMPLATES, new
StringReader(templateStr),templateConfiguartion);
emailTemplate.process(dataMap, out);
You can use vars for special variables:
${.vars["employee name"]}
vars: Expression .vars.foo returns the same variable as expression foo. It's useful if for some reasons you have to use square bracket syntax, since that works only for hash sub variables, so you need an artificial parent hash. For example, to read a top-level variable that has a strange name that would confuse FreeMarker, you can write .vars["A strange name!"].