boolean | No |
| trueDetermine whether to display the cycle. |
|
{section loop = $varName[, start = $start, step = $step, max = $max, show = true]}
name: The name of the section, not used 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 , determine whether to display this block, the default is true
There is a noun that needs to be explained:
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 loop index before
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. In the template design We have used it in part. This 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.
{section} block has attribute values, respectively:
1. index: the "loop 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 to count the number of loops in the section after the section block
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 function declaration and is used to determine whether the section is displayed
*foreach loop
1. foreach: used to loop simple arrays , it is a selective section loop, and its definition format is:
{foreach from=$array item=array_id}
{foreachelse}
{/foreach}
where, from indicates the The array variable to be looped, item is the name of the variable to be looped, and the number of loops is determined by the number of array variables specified by from. {foreachelse} is used to process when the array passed in the program is empty. The following is a simple example:
====================== =====================
example6.tpl
==================== =======================
<html>
<head><title>这是一个foreach使用的例子</title></head>
<body>
这里将输出一个数组:<br>
<{foreach from=$newsArray item=newsID}>
新闻编号:<{$newsID.newsID}><br>
新闻内容:<{$newsID.newsTitle}><br><hr>
<{foreachelse}>
对不起,数据库中没有新闻输出!
<{/foreach}>
</body>
</html>