Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Velocity template variable name with a special character - a dot

I need to access a value of a Velocity template's variable named:

$myFeature.enabled

Mind the dot within the name. It is defined in the code as:

myFeature.enabled=true

The problem is that, when I want to get the value of that variable withing html context with the following expression:

'${myFeature.enabled}'

it is not resolved and just gives:

"${myFeature.enabled}"

I tried to escape the dot with \ or change apostrophes to " but without luck.

Changing the name of the variable to a one without a dot is not an easy option for various reasons, so please suggest any other solutions.

like image 934
Blaise Avatar asked Dec 04 '22 06:12

Blaise


1 Answers

The answer is as simple as:

Velocity variable naming: does not allow dots within variable

Also here:

To use a $SINGLE.VARIABLE.IDENTIFIER.WITH.DOTS no backslash is required. The engine will not treat such expression as a variable to be processed because a Velocity variable cannot contain dots according to the Velocity variable notation.

Links:

  • http://velocity.apache.org/engine/devel/vtl-reference-guide.html
  • http://www.jetbrains.com/idea/webhelp10.5/escaping-characters-in-velocity-variables-and-directives.html
like image 134
Blaise Avatar answered Dec 09 '22 15:12

Blaise