Smarty中的iteration,index学习备忘

.iteration

iteration contains the current loop iteration and always starts at one, unlike index. It is incremented by one on each iteration.

iteration包含当前循环次数,与index不同,从1开始,每次循环增长1。

.index

index contains the current array index, starting with zero.

.index包含当前数组索引,从零开始。

每行显示5条数据

<!–{foreach from=$this_week_list item=value key=key}–>

{if $key mod 5 == 0}

<br>

{/if}

<a href=”goods.php?id={$value.goods_id}” ><img src=”{$value.goods_thumb}”></a>

<!–{/foreach}–>

<!–{foreach from=$this_week_list item=value key=key}–>

{if $smarty.foreach.foo.index % 5 == 0}

<br/>

{/if}

<a href=”goods.php?id={$value.goods_id}” ><img src=”{$value.goods_thumb}”></a>

<!–{/foreach}–>

<!–{foreach from=$this_week_list item=value key=key}–>

<a href=”goods.php?id={$value.goods_id}” ><img src=”{$value.goods_thumb}”></a>

{if $smarty.foreach.foo.iteration mod 5 eq 0}

<br>

{/if}

<!–{/foreach}–>

Leave a comment

Your comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word