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

foreach help

Discussion in 'XenForo Development Discussions' started by covort, Aug 22, 2012.

  1. covort

    covort New Member

    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>
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
    bousaid and sonnb like this.
  3. covort

    covort New Member

    t
    Thank you :)
     

Share This Page