tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/9010-velocity-foreach-count-evenoddCascade CMS: Discussion 2018-10-18T20:37:03Ztag:help-archives.hannonhill.com,2010-02-09:Comment/311380202014-01-15T22:08:47Z2014-01-15T22:08:47ZVelocity foreach count, even/odd<div><p>Hi Ashley,</p>
<p>You should be able to accomplish this by using the
<code>$_MathTool.mod()</code> method and
<code>$foreach.index</code>. Try something like the following and
let me know how it works out:</p>
<pre>
<code>#foreach(...)
#set ($imageColor = "white")
#if ($_MathTool.mod($foreach.index, 2) == 1)
#set ($imageColor = "red")
#end
## $imageColor will be "white" for even and "red" for odd
#end</code>
</pre>
<p>Note: depending on your use case, you may nee to switch the two
colors around.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/311380202014-01-15T22:20:37Z2014-01-15T22:20:37ZVelocity foreach count, even/odd<div><p>That's just what I needed, thank you!</p></div>Ashley Williams