Chris Becker
Chris Becker

Reputation: 43

Velocity hasNext method

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!

Upvotes: 4

Views: 9217

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

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.

Upvotes: 6

Related Questions