我通常不是一个聪明人,所以我有点卡住了。
我想回显数组的索引,但我想每次回显时都增加它。
这就是我所拥有的...
<ul>
{foreach from=$gallery key=index item=image}
<li>
<img src="{$image}" alt="" id="panel-{$index++}" />
</li>
{/foreach}
</ul>
这不起作用。
在将数组交给 Smarty 之前对其进行预处理是最好的方法吗?
有没有办法使用 Smarty 来做到这一点?
您可以执行以下操作:
<ul>
{foreach from=$gallery key=index item=image name=count}
<li>
<img src="{$image}" alt="" id="panel-{$smarty.foreach.count.index}" />
</li>
{/foreach}
</ul>
从零开始,index
是当前数组索引。
然而,这可能是最好的方法,只需使用counter http://www.smarty.net/docsv2/en/language.function.counter.tpl之外的foreach
你可以使用循环counter
,像这样:
{counter start=0 skip=1 assign="count"}
要增加它,只需调用{counter}
在每次迭代时。
{counter}
{*Can then use the $count var*}
{if $count is div by 4}
{*do stuff*}
{/if}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)