Menu

problem with #set

Help
2007-05-15
2013-05-02
  • Sébastien Revel

    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

     
    • Tobias Riemer

      Tobias Riemer - 2007-05-15

      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

       
    • kazoolist

      kazoolist - 2009-03-07

      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.

       

Log in to post a comment.