tags:

views:

63

answers:

1

Looks like set does not work in velocity when written as below :

#set (${modifier} = "some")

It works if I do #set ($modifier = "some"). Any reason for this?

EDIT : It doesn't work means no variable is set.

+2  A: 

It is because ${varname} is not a valid variablename in velocity as defined in the reference manual

I am also often confused on these seemingly random syntax changes.

Peter Tillemans
I guess you can reference a var as ${varname} but define it like that.
fastcodejava
@Peter Tillemans: i don't think the syntax was changed in the last 10 years - it was so even in WebMacro (Velocity's grandfather).Variables are defined simply using just the $ sign. The curly braces are used when reference objects and their subobject graph and to separate them from the environment: e.g. where text wold continue just at the end of the variable, so Velocity needs to now what's the text and what's the variable.
A. Ionescu
I was referring to contextual changes. Velocity use the same principles as bash and perl to fix the problem of differentiating between varname and the rest of the text.
Peter Tillemans