Freemarker Reserved Characters

Freemarker syntax has some reserved characters like other programming languages. This will cause unnecessary debugging when you find errors happening without reasons. So, one of the checks you need to do is to check for reserved characters in your variable naming.

Reserved Characters to Note

These are the reserved characters you must take note in your naming of variables.

How can I use variable names (macro name, parameter name) that contain minus sign (-), colon (:), dot (.), or or other special characters?

Source: Freemarker FAQ

Freemarker will not read the variable correctly if there is a special characters like “events-id”. You will be getting errors for Freemarker even if your syntax is correct.

How to Fix

These are some recommended solutions to fix them.

  • Remove the special characters.
  • Escape the characters with slash. “events\-id”.
  • Enclosed the variables with square brackets [“events-id”]
  • Assign the variables to your local variable name.

Freemarker is fussy with some of the reserved characters in variables naming. You need to take care not to include this when you name your variables. The easiest solution is to change the variable name. If the variable name cannot be changed, it is recommended to try other solutions to fix the name. My preferred solution will be assignment of the variable to my local variable name is the next best choice.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s