Php-Smarty-5 (22), phpsmarty-522. Php-Smarty-5 (22), phpsmarty-522 connected to the previous 11, section, sectionelsesection is a loop structure statement, mainly used to traverse the array syntax: {sectionname name loop php-Smarty-5 (22), phpsmarty-522
Next
11. section and sectionelse section are loop structure statements used to traverse arrays.
Syntax:
{Section name = name loop = loop array (times) start = start (0) step = step (1) max = maximum number of cycles}
{Sectionelse}
{/Section}
Name: Required for section statement naming
Loop: Required for Loop array
Start: Start Index default value: 0
Step: Step size default value: 1
Max: maximum number of cycles default value: total length
Differences between Foreach and section:
Foreach refers to directly traversing an array.
Section is a loop statement. its number of loops is determined by the number of arrays.
Section is more selective in traversing arrays.
L section built-in variables
{$ Smarty. section. name. index} cyclic index
{$ Smarty. section. name. index_prev} previous cyclic index
{$ Smarty. section. name. index_next} next cycle index
{$ Smarty. section. name. iteration} the cyclic index starts from 1.
The values {$ smarty. section. name. first | last} are true for 1st and last execution.
Total number of {$ smarty. section. name. total} cycles
12. strip remove consecutive spaces
Syntax:
{Strip}
......
{/Strip}
II. user-defined functions
1. Create Template variables for assign
{Assign var = "var" value = "value "}
Var: specifies the variable name.
Value: specifies the variable Value.
2. counter counters
Syntax:
{Counter start = 0 skip = 2 print = false}
Start: Start value
Skip: the default step size is 1.
Print: whether to output this time
3. cycle rotation
Values: list of Values to rotate
4. debug open debugging window
5. eval calculates the variable value.
Syntax:
{Eval var = # ErrorState # assign = "state_error "}
Var: name of the variable to be calculated
Assign: saves the result, but does not output this time.
6. fetch reads and outputs the file content
{Fetch file = "file" assign = "var "}
File: File name
Assign: save the result and do not output it this time.
7. print an image on the html_image page.
{Html_image file = "pumpkin.jpg "}
File: Image address
8. html_table displays the array elements in the table (only applicable to simple arrays)
{Html_table loop = $ data cols = 4 table_attr = 'border = "0 "'}
Loop: required for the array to be traversed
Cols: the number of cells displayed in each row is three by default.
Table_asd: table attributes
9. print a set of check boxes in html_checkboxes
{Html_checkboxes values = $ cust_ids checked = $ customer_id output = $ cust_names separator ="
"}
Values: array of Values
Checked: array of the values of the selected items
Output: text array
Separator: Separator separated between multiple options
Name: Name this set of check boxes. note: [] is automatically added to smarty, indicating that it is an array.
Template code:
Php code:
Http://www.bkjia.com/PHPjc/993262.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/993262.htmlTechArticlephp-Smarty-5 (22), phpsmarty-522 connected to the previous 11, section, sectionelse section is a loop structure statement, mainly used to traverse the array syntax: {section name = name loop = loop...