smarty的foreach的參數表如下
Attribute Name屬性名稱 | Type類型 | Required必要 | Default默認值 | Description描述 |
---|---|---|---|---|
from | array數組 | Yes必要 | n/a |
The array you are looping through 循環訪問的數組 |
item | string字符串 | Yes必要 | n/a |
The name of the variable that is the current element 當前元素的變量名 |
key | string字符串 | No可選 | n/a |
The name of the variable that is the current key 當前鍵名的變量名 |
name | string字符 | No可選 | n/a |
The 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}-->
下面代碼會打印出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值。