Question

Using freemarker, is there any way to reference a value indirectly along the lines of...

<#assign apple=fruit>
<#assign item=apple>
${${item}}

to produce the output 'fruit' without prior knowledge of what value item might contain?

Was it helpful?

Solution

You can try using eval built-in:

${item?eval}

That would only work if item contains a valid expression, though. There's also an interpret built-in which treats your string as a full template, I haven't used it myself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top