snarty foreach name的使用

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}-->

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值。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章