I try to modify a vsl file for code generation to check whether a foreach loop is actually entered and the initialization code is to be performed at all. I tried java-like .length > 0 but that does not work:
myMethod() {
#if (${reference.attributes}.length > 0)
[some init code]
#foreach ($attribute in ${reference.attributes})
#some_macro($attribute)
#end
[some other code related to stuff created in the
#end
}
What’s the correct way?
Thanks.
Call the
size()method. This will work on both collections and arrays (as of Velocity 1.6+).