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
<Tr bgcolor = "{cycle values =" # eeeeee, # d0d0d0 "}">
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 = "<br/> "}
Values: array of Values
Checked: array of the value of the selected item
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: