Home >Backend Development >PHP Tutorial >Introduction and usage analysis of smarty section_PHP tutorial
The basic prototype is:
{section name = name loop = $varName[, start = $start, step = $step, max = $max, show = true]}
name: the name of the section, no need to add $
$loop: The variable to be looped. Use assign to operate on this variable in the program.
$start: The subscript to start the loop. The loop subscript starts from 0 by default.
$step: The increment of the subscript during each loop.
$max: The maximum loop subscript.
$show: boolean type. , determines whether to display this block, the default is true
There is a noun that needs explanation:
Loop subscript: Its actual English name is index, which means index. Here I will translate it It is called "subscript" mainly for easier understanding. It represents the current loop index when displaying this loop block. It starts from 0 by default and is affected by $start. If $start is set to 5, it will also start counting from 5. We have used it in the template design part. This It is an attribute of the current {section}. The calling method is Smarty.section.sectionName.index. The sectionName here refers to the name attribute in the function prototype. The attribute values of the
{section} block are:
1. index: the "cyclic subscript" we introduced above, the default is 0
2. index_prev: the previous value of the current subscript, the default It is -1
3. index_next: the next value of the current index, the default is 1
4. first: whether it is the first cycle
5. last: whether it is the last cycle
6. iteration: the number of loops
7. rownum: the current row number, another alias of iteration
8. loop: the last loop number, which can be used after the section block to count the number of loops in the section
9. total: The number of loops can be used to count the number of loops after the section block
10. show: It is included in the declaration of the function and is used to determine whether the section is displayed.