snarty foreach name的使用

来源:互联网 发布:tumblr类似的软件 编辑:程序博客网 时间:2024/06/03 16:51

smarty的foreach的参数表如下


Attribute Name属性名称Type类型Required必要Default默认值Description描述fromarray数组Yes必要n/aThe array you are looping through
循环访问的数组itemstring字符串Yes必要n/aThe name of the variable that is the current element
当前元素的变量名keystring字符串No可选n/aThe name of the variable that is the current key
当前键名的变量名namestring字符No可选n/aThe name of the foreach loop for accessing foreach properties
用于访问foreach属性的foreach循环的名称

对于name的属性使用有如下例子

index 一下代码每五次循环打印@@@@一次 index从零开始

<!--{foreach from=$list item=val key=key name=foo}-->
<!--{if $smarty.foreach.foo.index % 5 == 0}-->
<p>@@@@@</p>
<!--{/if}-->
<!--{/foreach}-->

iteration 包含当前循环次数和index不一样,从1开始

下面代码会打印出0/1 1/2 2/3 3/4 4/5...

<!--{foreach from=$list item=val key=key name=foo}-->
<!--{$smarty.foreach.foo.index}-->/<!--{$smarty.foreach.foo.iteration}-->
<!--{/foreach}-->

对于foreach循环的的属性可以这样来标示每个属性 name=" <!--{$smarty.foreach.foo.iteration}-->"

然后在后台php通过POST来获取对应的value值。

0 0
原创粉丝点击