Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Velocity hasNext method

Tags:

velocity

I am attempting to invoke the hasNext method in a Velocity template, in order to effect behavior based on the position in a foreach loop - only hasNext is not working as documented.

Here is a snippet from the Velocity user guide, on the use of hasNext:

Velocity also now provides an easy way to tell if you are on the last iteration of a loop:

#foreach( $customer in $customerList )
  $customer.Name#if( $foreach.hasNext ),#end
#end

Here is my version:

#foreach ($nav_item in $priNavItems)
  ...
  #if ( $foreach.hasNext )
    <img alt="" class="dive" src="/olp-theme/images/custom/dive.png">
  #end
#end

Has anyone been successful in invoking this method in a #foreach loop in a Velocity template? Perhaps under a different name (like $velocityCount for count)?

Any/all advice and or direction appreciated - thanks!

like image 624
Chris Becker Avatar asked Oct 18 '25 18:10

Chris Becker


1 Answers

This is not supported in Velocity 1.6.3; the $foreach.hasNext functionality is provided by the ForeachScope class of 1.7+ (docs).

The online docs refer to the current version; when working with earlier versions you need to refer to that specific version's docs.

like image 173
Dave Newton Avatar answered Oct 22 '25 08:10

Dave Newton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!