如何在迭代中获取第二个项目?

时间:2016-10-11 09:35:12

标签: foreach smarty

我得到第一个这样的项目:

{foreach $sArticle.sBlockPrices as $blockPrice}
  {if $blockPrice@first}
    First element
  {else}
    ...
  {/if}
{/foreach}

如何获得第二/第三项?

1 个答案:

答案 0 :(得分:0)

使用此处引用的foreach的index属性:http://www.smarty.net/docsv2/en/language.function.foreach.tpl

尝试这样的事情:

{foreach name=$sArticle.sBlockPrices item=$blockPrice name=blockPrices}
  {if $smarty.foreach.blockPrices.index == 2}
    ...
  {/if}
{/foreach}