On 05/30/2011 08:36 PM, Robert Lee wrote:
I have tried
#set($n = 2)
#set($range = "[1..$n]")
#foreach($i in $range)
as well Velocity 1.7 fails when it reaches the range variable in the
#foreach directive.

Is there a way to accomplish what I am trying to do, (a variable count
loop) in velocity?

The error is that you're not actually iterating over a range, but trying to iterate over a string.

#set($range = "[1..$n]") => $range is a String
#foreach($i in $range) => $range is still a String, it won't be replaced with [1..$n]

This should work:

#set($n = 2)
#foreach($i in [1..$n])

If you must define the range somewhere else as a string, you can use #evaluate to dynamically interpret the range, but that adds unneeded complexity.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org

Reply via email to