0

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?

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • 1
    Awww. I don't think it's worth a bad-question vote just because it's documented. :-) Every time I'm away from FreeMarker for a few weeks I mess this distinction up. I think it's because it looks so Perl-y and Perl would be happy with the `${}` way everywhere. – Nathaniel Waisbrot Apr 11 '13 at 19:24

1 Answers1

2

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.

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99