Assigning a variable to an object in Freemarker templates
freemarker, templates
Solution
It is possible, like this:
<#assign thisGuy = outter.inner.assignThisGuy>
...
${thisGuy.field1}
Problem
I am trying to avoid repeatedly refering to objects like this: ``` ${outter.inner.assignThisGuy.field1} ``` and would like to refer to lowest level, i.e. ``` ${assignThisGuy.field1} ``` This will help me remove repeated null checks and make my template tidier. I'm not sure if this is possible. All the notes refer to assigning a variable to a type like ?string, ?date, etc. When I try to do it I get an exception: ``` freemarker.template.TemplateException: Expected hash. thisGuy evaluated instead to freemarker.template.SimpleScalar ``` I have tried variations on: ``` [#assign thisGuy = "${outter.inner.assignThisGuy}" ] ``` I just want to be sure this is not possible before some of my lines become massive in length!