Question

I am having something similar to the following in one of my templates:

<#assign myVar = ${myValue}-1>

but Freemarker is not happy and gives me:

Exception in thread "main" freemarker.core.ParseException:
    Encountered "{" at line 43, column 43 in myTemplate.ftl.
Was expecting one of:
    "in" ...
    ">" ...
    <EMPTY_DIRECTIVE_END> ...
    etc...

Is there any way I can use/retrieve the value of myValue and use it in a directive?

Was it helpful?

Solution

Yes there is:

<#assign myVar = myValue - 1 >

(There's an example similar to this in the documentation for assign)

The ${} syntax is used when you're outside of a FreeMarker directive and need to attract its attention to do interpolation. Within FreeMarker tags, though, variables must be bare.

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