smarty2.x foreach 和section的使用

foreach

Attribute NameTypeRequiredDefaultDescription
fromarrayYesn/aThe array you are looping through
itemstringYesn/aThe name of the variable that is the current element
keystringNon/aThe name of the variable that is the current key
namestringNon/aThe 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
namestringYesn/aThe name of the section
loopmixedYesn/aValue to determine the number of loop iterations
startintegerNo0The 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.
stepintegerNo1The 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.
maxintegerNon/aSets the maximum number of times the section will loop.
showbooleanNotruedetermines 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的开始标签为"<{", 结束标签为"}>"

 

转载于:https://www.cnblogs.com/ainiaa/archive/2010/04/06/smarty2-foreach-section.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值