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 $smarty.foreach.foo.first}
        

This is the first item from the array!

{/if} {if $smarty.foreach.foo.last}

This is the last item from the array!

{/if} {/foreach}

OR

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

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

Views (887)

Share on Facebook0Share on Google+0Share on LinkedIn0Tweet about this on TwitterEmail this to someonePrint this page
[Total: 1    Average: 5/5]

Leave a Reply

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

twelve + 5 =