Velocity2js assumes that the left operand in the set directive (in this case: realId) is a local variable.
To solve this problem I will add the possibility to force the left operand to be a context variable.
The syntax will be as followed:
My $0.02: This behavior seems to be inconsistent with Apache's velocity, where sets do not change local variables, but change the state within the context. I came across velocity2js because I'm looking for a templating system I can use across platforms (Java, JS, python via airspeed, etc) but this behavior would seem to interfere with that goal.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I have this line in my vm
#set ($realId = "${id}")
I obtain
var realId = context.id
in my js
It must be context.realId = context.id . If not, in my vm, $realId bugs !
Secondly, in my vm
#set ($id = "${id}Cal")
must be transformed in
context.id = context.id+"Cal" beacause the $ is not escaped
Thks
First problem:
Velocity2js assumes that the left operand in the set directive (in this case: realId) is a local variable.
To solve this problem I will add the possibility to force the left operand to be a context variable.
The syntax will be as followed:
#set($context.realId = ${id})
see tracker: http://sourceforge.net/tracker/index.php?func=detail&aid=1719411&group_id=194675&atid=950379
Second problem:
use (this will work in the current version): #set ($x = ${id} + "Cal")
this will generate following output: var x = context.id + "Cal";
use (will work in upcoming version): #set ($context.id = ${id} + "Cal")
to get: context.id = context.id+"Cal";
thx for using and testing velocity2js
My $0.02: This behavior seems to be inconsistent with Apache's velocity, where sets do not change local variables, but change the state within the context. I came across velocity2js because I'm looking for a templating system I can use across platforms (Java, JS, python via airspeed, etc) but this behavior would seem to interfere with that goal.