Search code examples
htmlsmarty

Smarty - foreach stops while reaching a limit


i have a smarty foreach loop over a list of elements. this loop must stop when it complete 10 iteration, ie foreach must end at the 10th element of list.

{foreach $b_list as $list}
     <label>{$list['firstname']}</label>
{/foreach}

Solution

  • {foreach $b_list as $list name=list10}
        {if $smarty.foreach.list10.index == 10}
            {break}
        {/if}
        <label>{$list['firstname']}</label>
    {/foreach}