?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
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í)行的初始位置. 如果該值為負(fù)數(shù),開始位置從數(shù)組的尾部算起. 例如:如果數(shù)組中有7個(gè)元素,指定start為-2,那么指向當(dāng)前數(shù)組的索引為5. 非法值(超過(guò)了循環(huán)數(shù)組的下限)將被自動(dòng)調(diào)整為最接近的合法值. |
step | integer | No | 1 | 該值決定循環(huán)的步長(zhǎng). 例如指定step=2將只遍歷下標(biāo)為0、2、4等的元素. 如果step為負(fù)值,那么遍歷數(shù)組的時(shí)候從后向前遍歷. |
max | integer | No | 1 | 設(shè)定循環(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 標(biāo)簽必須成對(duì)出現(xiàn). 必須設(shè)置 name 和 loop 屬性. 名稱可以是包含字母、數(shù)字和下劃線的任意組合. 可以嵌套但必須保證嵌套的 name 唯一. 變量 loop (通常是數(shù)組)決定循環(huán)執(zhí)行的次數(shù). 當(dāng)需要在 section 循環(huán)內(nèi)輸出變量時(shí),必須在變量后加上中括號(hào)包含著的 name 變量. sectionelse 當(dāng) loop 變量無(wú)值時(shí)被執(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)用的變量名. 通過(guò)如下方式調(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},老版本的格式依然支持,但在手冊(cè)的例子中只提供新的格式.