How to find first and last index of foreach loop in smarty

When we do a coding with the Prestashop sometime we need to find whether first/last index of foreach loop.
There are 2 ways to find first or last index of foreach loop in the smarty. I will show you some of example for that.

{foreach from=$arrList key=myId item=i name=foo}
    {if $}

This is the first item from the array!

{/if} {if $}

This is the last item from the array!

{/if} {/foreach}


{* Add horizontal rule at end of list *}
{foreach $items as $item}
  {$}{if $item@last}
{else},{/if} {foreachelse} ... no items to loop ... {/foreach}

{foreach} properties are @index, @iteration, @first, @last, @show, @total.

Views (3679)

Leave a Reply

Your email address will not be published. Required fields are marked *

19 + ten =