2016-12-01 51 views
0

因此,現在使用cscart一段時間後,每天學習,我遇到了一些我覺得很煩人的東西。Smarty目標最後一項

因此,無論何時向功能添加多個值,它都會顯示它們,如f.e. 「OrangeGreen」,而我想讓它看起來像「橙色,綠色」。好像看起來很簡單,只是改變產品功能。

{elseif in_array($feature.feature_type, ["ProductFeatures::TEXT_SELECTBOX"|enum, "ProductFeatures::EXTENDED"|enum, "ProductFeatures::NUMBER_SELECTBOX"|enum])} 
       {foreach from=$feature.variants item="var"} 
        {if $var.selected}{$var.variant}, {/if} 
       {/foreach} 

但現在它不會是「橙色,綠色」。現在它是「橙色,綠色,」

所以你們可以幫助我,並找出我如何可以定位這段代碼中的最後一項?

回答

1

您可以使用foreach循環的屬性,如索引,第一個和最後一個來訪問此循環中的特定元素。

在Smarty的V2您的foreach循環需要一個name屬性來訪問它的屬性:

{foreach from=$feature.variants item="var" name="features"} 
    {if $var.selected}{$var.variant}, {/if} 
    {if $smarty.foreach.features.last} this is the last element in this loop{/if} 
{/foreach} 

(文檔:http://www.smarty.net/docsv2/en/language.function.foreach.tpl#foreach.property.last

Smarty的V3還要simplier:

{if [email protected]} this is the last element in this loop{/if} 

(docs:http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.last

對不起,我不確定cs-cart是否支持Smarty V2或V3

+0

是的,cscart使用smarty來處理模板。 (V3) – SimplySavage

相關問題