smarty2.x foreach 和section的使用

foreach

Attribute NameTypeRequiredDefaultDescription
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

 

iteration

iteration is used to display the current loop iteration.

Iteration always starts with 1 and is incremented by one one each iteration.

访问方法为:$smarty.foreach.foreachname.iteration. 其中 foreach 为当前foreach的 name 属性

first

first is set to true if the current foreach iteration is the first one.

访问方法为:$smarty.foreach.foreachname.first. 其中 foreach 为当前foreach的 name 属性

last

last is set to true if the current foreach iteration is the last one.

访问方法为:$smarty.foreach.foreachname.last. 其中 foreach 为当前foreach的 name 属性

show

show is used as a parameter to foreach. show is a boolean value, true or false. If false, the foreach will not be displayed. If there is a foreachelse present, that will be alternately displayed.

访问方法为:$smarty.foreach.foreachname.show. 其中 foreach 为当前foreach的 name 属性

total

total is used to display the number of iterations that this foreach will loop. This can be used inside or after the foreach.

访问方法为:$smarty.foreach.foreachname.total. 其中 foreach 为当前foreach的 name 属性 

 

section

Attribute NameTypeRequiredDefaultDescription
name string Yes n/a The name of the section
loop mixed Yes n/a Value to determine the number of loop iterations
start integer No 0 The index position that the section will begin looping. If the value is negative, the start position is calculated from the end of the array. For example, if there are seven values in the loop array and start is -2, the start index is 5. Invalid values (values outside of the length of the loop array) are automatically truncated to the closest valid value.
step integer No 1 The step value that will be used to traverse the loop array. For example, step=2 will loop on index 0,2,4, etc. If step is negative, it will step through the array backwards.
max integer No n/a Sets the maximum number of times the section will loop.
show boolean No true determines whether or not to show this section

 

index

index is used to display the current loop index, starting with zero (or the start attribute if given), and incrementing by one (or by the step attribute if given.)

Technical Note: If the step and start section properties are not modified, then this works the same as the iteration section property, except it starts on 0 instead of 1.

方法该属性的方法为:$smarty.section.sectionname.index//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"
 

index_prev

index_prev is used to display the previous loop index. on the first loop, this is set to -1.

方法该属性的方法为:<{$smarty.section.sectionname.index_prev}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

index_next

index_next is used to display the next loop index. On the last loop, this is still one more than the current index (respecting the setting of the step attribute, if given.)

方法该属性的方法为:<{$smarty.section.sectionname.index_next}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

iteration

iteration is used to display the current loop iteration.

Note: This is not affected by the section properties start, step and max, unlike the index property. Iteration also starts with 1 instead of 0 like index. rownum is an alias to iteration, they work identical.

方法该属性的方法为:<{$smarty.section.sectionname.iteration}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

rownum

rownum is used to display the current loop iteration, starting with one. It is an alias to iteration, they work identically.

方法该属性的方法为:<{$smarty.section.sectionname.rownum}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

first

first is set to true if the current section iteration is the first one.

方法该属性的方法为:<{$smarty.section.sectionname.first}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

loop

loop is used to display the last index number that this section looped. This can be used inside or after the section.

方法该属性的方法为:<{$smarty.section.sectionname.loop}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

show

show is used as a parameter to section. show is a boolean value, true or false. If false, the section will not be displayed. If there is a sectionelse present, that will be alternately displayed.

方法该属性的方法为:<{$smarty.section.sectionname.show}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

total

total is used to display the number of iterations that this section will loop. This can be used inside or after the section.

方法该属性的方法为:<{$smarty.section.sectionname.total}>//其中sectionname 为当前section的名字, 假设smarty的开始标签为"<{", 结束标签为"}>"

 

posted @ 2010-04-06 22:35  浪淘沙(Jeff.Liu)  阅读(1017)  评论(0)    收藏  举报