Search code examples
loopsfor-loopvelocity

"for" loop in velocity template


I already posted a similar question a week ago on How to use 'for' loop in velocity template?.

So...basically I can't use 'for' loop in a velocity template.

Let's say I have a variable that holds integer 4. I want to display something four times using that variable. How do I do it in a velocity template?


Solution

  • Try to do it like this:

    #set($start = 0)
    #set($end = 4)
    #set($range = [$start..$end])
    #foreach($i in $range)
       doSomething
    #end
    

    The code has not been tested, but it should work like this.