【问题标题】:Multiple counter in Smarty TemplateSmarty 模板中的多个计数器
【发布时间】:2015-03-02 04:41:39
【问题描述】:

我有一个名为 Listings 的数组。我如何获得多个计数器。在下面给出的示例中,我得到条件为一的数字。我需要一个计数器来获取条件为 0 的数字。我希望使用相同的 foreach 循环得到结果,并且不想创建一个新的 foreach 循环。

{counter  start=1 print=0}
{foreach from=$listings item=listing}

    {if $listing.condition == '1'}
        {counter print=0}
    {/if}


{/foreach}

{counter}  // This givens me total count where condition is 1.

【问题讨论】:

    标签: php foreach smarty


    【解决方案1】:

    为每个计数器使用名称。

    {counter name=condition_1 start=1 print=0}
    {counter name=condition_0 start=1 print=0}
    {foreach from=$listings item=listing}
        {if $listing.condition == '1'}
            {counter name=condition_1 print=0}
        {else}
            {counter name=condition_0 print=0}
        {/if}
    {/foreach}
    {counter name=condition_1}
    {counter name=condition_0}
    

    http://www.smarty.net/docs/en/language.custom.functions.tpl#language.function.counter

    【讨论】:

      猜你喜欢
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 2011-01-17
      相关资源
      最近更新 更多