smarty如何在循环过程中取得索引

很多时候我们会使用到ecshop的foreach标签去循环显示商品,那么问题是我们一般使用php的循环时都有一个变量来控制次数和取得每次循环的索引,比如那个i,使用foreach时如何取到呢,很简单,我们给它定义一个名字就行了,如下例所示。

<!-- {foreach name=top_goods from=$top_goods item=goods}-->
       <div class="topgoodslist"> 
  <!-- {if $smarty.foreach.top_goods.iteration==1}-->
   <a href="/{$goods.url}"  class="topsale1" title="{$goods.name|escape:html}"><img src="/{$goods.goods_img}" alt="{$goods.name|escape:html}"/></a>
 <!--{/if}-->

<!--{/foreach}-->

这里 $smarty.foreach.top_goods.iteration  就是取得索引的方法。

你可能感兴趣的:(smarty如何在循环过程中取得索引)