筆者在這里分享一個ecshop在模板循環中 輸出變量自動加1,因為很多人在特殊的樣式下 div 的id 值是自動加1的,例如:duo1,duo2,duo3,我下面用一個案例進行說明,
<!--{if $helps}-->
<!-- {foreach from=$helps item=help_cat name=help} -->
<dl>
<dt><span>class="dt_ico art_ico<!--{$smarty.foreach.help.iteration}-->"</span><span>{$help_cat.cat_name}</span></dt>
<!-- {foreach from=$help_cat.article item=item} -->
<dd>
<a href="{$item.url}" title="{$item.title|escape:html}">{$item.short_title}</a>
</dd>
<!-- {/foreach} -->
上面標注紅色的地方就是變量自動加以 用到了smarty 的iteration屬性
</dl>
<!-- {/foreach} -->
<!-- {/if} -->
新聞熱點
疑難解答