How to use 'for' loop in velocity template?

Moon picture Moon · Apr 16, 2011 · Viewed 48.7k times · Source

I just googled for 'for loop', but it looks like velocity has 'foreach' only.

How do I use 'for loop' in velocity template?

Answer

serg picture serg · Apr 16, 2011

Wanted to add that iteration information inside foreach loop can be accessed from special $foreach property:

#foreach ($foo in $bar)
    count: $foreach.count
    index: $foreach.index
    first: $foreach.first 
    last:  $foreach.last
#end

(last time I checked last contained a bug though)