Velocity and $foreach.count

yannisf picture yannisf · Oct 4, 2011 · Viewed 44.6k times · Source

I am using velocity 1.7 and within a foreach loop I want to print the count. In the template I have the following string in a #foreach/#end section:

Count: $foreach.count

and was expecting to see in the rendered result something like

Count: 1
...
Count: 2
...

but all I see is:

Count: $foreach.count
...
Count: $foreach.count
...

Any ideas what am I doing wrong?

Answer

summerbulb picture summerbulb · Oct 21, 2011

Neither $foreach.count nor $counter worked for me.

This answer suggests using $velocityCount, and it worked for me.