Velocity and $foreach.count

I tried with $counter & $foreach.count but neither of these worked for me.

However, the $velocityCount tag worked and below is the example.

Input code:

#foreach($entry in $entries)    
    <p>In for Loop count is : $velocityCount</p>     
#end    

Output:

In for Loop count is : 1

In for Loop count is : 2

In for Loop count is : 3

Your code is partial, we don't see the foreach directive.

Else, I know that the foreach loop has a built-in variable called $counter, though in the guide they do refer to $foreach.count


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

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


I do not know why the foreach loop built-in variable called $count is not working as guide refer. But $velocityCount is worked for me.

There is property called directive.foreach.counter.name is velocityCount in velocity.properties file, so default $count variable may not be working.