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

XF 1.5 Foreach loop

Discussion in 'XenForo Questions and Support' started by Lee, Jul 7, 2016.

  1. Lee

    Lee Well-Known Member

    I have this loop that i'm using in my heavily cutomised profile page. It selects every post to be submitted to the users profile. Is there a way to limit the amount of records selected?

    <xen:foreach loop="$profilePosts" value="$profilePost"> </xen:foreach>
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    You can add an i attribute to the loop and each iteration will increment i by one:

    Code:
    <xen:foreach loop="$profilePosts" value="$profilePost" i="$i">
        <xen:if is="$i < 5">
             // Do something
        </xen:if>
    </xen:foreach>
     
  3. Lee

    Lee Well-Known Member

    Syntax error using that code
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Sorry:

    Code:
    <xen:foreach loop="$profilePosts" value="$profilePost" i="$i">
        <xen:if is="{$i} < 5">
             // Do something
        </xen:if>
    </xen:foreach>
     

Share This Page