• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

foreach help

#1
Is there a way of me finding out which cycle of the loop i am currently on.

For example:

Code:
<xen:foreach loop="$RecentNews" value="$news">
<div class="{xen:if '{$loop.cyclenumber} % 2 == 1', 'primaryContentDark', 'primaryContent'}">
</xen:foreach>
 

Jake Bunce

XenForo moderator
Staff member
#2
Code:
<xen:foreach loop="$RecentNews" value="$news" i="$i" count="$count">
<div class="{xen:if '{$loop.cyclenumber} % 2 == 1', 'primaryContentDark', 'primaryContent'}">
</xen:foreach>
Now {$i} will increment for each iteration. {$count} will just have the total number of array elements.
 
#3
t
Code:
<xen:foreach loop="$RecentNews" value="$news" i="$i" count="$count">
<div class="{xen:if '{$loop.cyclenumber} % 2 == 1', 'primaryContentDark', 'primaryContent'}">
</xen:foreach>
Now {$i} will increment for each iteration. {$count} will just have the total number of array elements.
Thank you :)