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 (3584)
The following two tabs change content below.

Chris Mok
Senior Developer at GNA eMarketing
Core Contributor on the WordPress.org

Latest posts by Chris Mok (see all)
- WHM – Change account setup date manually - August 25, 2016
- Manually generate the notifications to who over disk quota - August 23, 2016
- Help Desk Management: What is Level 1, Level 2, and Level 3 Help Desk support? - July 27, 2016
- Find and delete files greater than a given size from the Linux command line - April 18, 2016
- How to change WordPress default email’s From name and address - April 15, 2016