Is it possible to refer a variable that contains dot in a freemarker template? (or '-' character)
e.g.:
Main.java:
public class Main {
public static void main(String[] args) throws IOException, TemplateException {
Configuration freemarkerConfig = new Configuration();
freemarkerConfig.setClassForTemplateLoading(Main.class, "");
Template template = freemarkerConfig.getTemplate("template.ftl");
Map<String, String> data = new HashMap<String, String>();
data.put("variable.name", "value");
Writer out = new StringWriter();
template.process(data, out);
System.out.println(out.toString());
}
}
template.ftl:
${variable.name}
This code throws exception:
The following has evaluated to null or missing:
==> variable [in template "template.ftl" at line 1, column 3]
Is it possible to refer the variable "variable.name" in the tempalte file?
It is possible with this syntax:
${.data_model["variable.name"]}
.data_model
is a special variable you can use to access the data-model directly.
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