I'm using the following foreach loop
#foreach( $product in $allProducts )
$product
#end
to get
something
something
something
something
something
something
Is it possible to wrap a div every 3 items in Velocity? For example to get the following result:
something
something
something
something
something
something
I tried using #if ($velocityCount % 3 == 0) in the foreach loop but it doesn't work.
解决方案
You did not tell us which Velocity version you were using. $velocityCount does not exist anymore in last versions (at least in 1.7.x). Try with $foreach.index:
#foreach( $product in $allProducts )
#if( $foreach.index %3 == 0 )
#if( !$foreach.first )