?
このドキュメントでは、 php中國語ネットマニュアル リリース
Attribute Name | Type | Required | Default | Description |
---|---|---|---|---|
name | string | Yes | n/a | The name of the section |
loop | [$variable_name] | Yes | n/a | The name of the variable to determine # 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 | 1 | Sets the maximum number of times the section will loop. |
show | boolean | No | true | determines whether or not to show this section |
屬性 | 類型 | 是否必須 | 缺省值 | 描述 |
---|---|---|---|---|
name | string | Yes | n/a | 該循環(huán)的名稱 |
loop | [$variable_name] | Yes | n/a | 決定循環(huán)次數(shù)的變量名稱 |
start | integer | No | 0 | 循環(huán)執(zhí)行的初始位置. 如果該值為負數(shù),開始位置從數(shù)組的尾部算起. 例如:如果數(shù)組中有7個元素,指定start為-2,那么指向當前數(shù)組的索引為5. 非法值(超過了循環(huán)數(shù)組的下限)將被自動調(diào)整為最接近的合法值. |
step | integer | No | 1 | 該值決定循環(huán)的步長. 例如指定step=2將只遍歷下標為0、2、4等的元素. 如果step為負值,那么遍歷數(shù)組的時候從后向前遍歷. |
max | integer | No | 1 | 設定循環(huán)最大執(zhí)行次數(shù). |
show | boolean | No | true | 決定是否顯示該循環(huán). |
Template sections are used for looping over arrays of data. All section tags must be paired with /section tags. Required parameters are name and loop . The name of the section can be anything you like, made up of letters, numbers and underscores. Sections can be nested, and the nested section names must be unique from each other. The loop variable (usually an array of values) determines the number of times the section will loop. When printing a variable within a section, the section name must be given next to variable name within brackets []. sectionelse is executed when there are no values in the loop variable.
模板的 section 用于遍歷數(shù)組中的數(shù)據(jù). section 標簽必須成對出現(xiàn). 必須設置 name 和 loop 屬性. 名稱可以是包含字母、數(shù)字和下劃線的任意組合. 可以嵌套但必須保證嵌套的 name 唯一. 變量 loop (通常是數(shù)組)決定循環(huán)執(zhí)行的次數(shù). 當需要在 section 循環(huán)內(nèi)輸出變量時,必須在變量后加上中括號包含著的 name 變量. sectionelse 當 loop 變量無值時被執(zhí)行.
Example 7-15. section
|
Example 7-16. section loop variable
|
Example 7-17. section names
|
Example 7-18. nested sections
|
Example 7-19. sections and associative arrays
|
Example 7-20. sectionelse
|
Sections also have their own variables that handle section properties. These are indicated like so: {$smarty.section.sectionname.varname}
Section 循環(huán)也有可供調(diào)用的變量名. 通過如下方式調(diào)用{$smarty.section.sectionname.varname}.
NOTE: As of Smarty 1.5.0, the syntax for section property variables has been changed from {%sectionname.varname%} to {$smarty.section.sectionname.varname}. The old syntax is still supported, but you will only see reference to the new syntax in the manual examples.
注意:Smarty 1.5.0 版中,section 名稱屬性變量的格式由{%sectionname.varname%}變成 {$smarty.section.sectionname.varname},老版本的格式依然支持,但在手冊的例子中只提供新的格式.