【问题标题】:How do I get the second Item in an Iteration?如何获得迭代中的第二个项目?
【发布时间】:2016-10-11 09:35:11
【问题描述】:

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

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

如何获得第二/第三项?

【问题讨论】:

    标签: foreach smarty


    【解决方案1】:

    使用这里引用的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}
    

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 2021-03-07
      • 2014-05-19
      • 1970-01-01
      相关资源
      最近更新 更多