2015-03-02 34 views
0

我有一個名爲listing的數組。我如何獲得多個計數器。在下面給出的例子中,我得到的條件是一個數字。我需要一個計數器來獲取條件爲0的數字。我想要使用相同的foreach循環的結果,並且不想創建新的foreach循環。Smarty模板中的多個計數器

{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. 

回答

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

+0

這工作。謝謝。 – 2015-03-02 05:09:31