循环标签语法
在index.html中:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>index模块index控制器index操作对应模板</p>
<table border="1" cellspacing="0" cellpadding="2" width="40%">
<caption style="font-size:22px;font-weight:bold">员工信息表</caption>
<tr style="background-color:#83daf1">
<th>编号</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>工资</th>
</tr>
<!-- volist循环 -->
{volist name="user" id="vo" key='k' offset="2" length="5" empty="没有数据"}
<tr>
<td>{$k}</td>
<td>{$vo.name}</td>
<td>{$vo.sex}</td>
<td>{$vo.age}</td>
<td>{$vo.salary}</td>
</tr>
{/volist}
</table>
</body>
</html>
<!-- foreach循环 -->
{foreach name="user" item="value"}
<tr>
<td>{$key}</td>
<td>{$value.name}</td>
<td>{$value.sex}</td>
<td>{$value.age}</td>
<td>{$value.salary}</td>
</tr>
{/foreach}
<!-- for循环 -->
{for start='0' end='10' comparsion='lt' name='i' step='1'}
<tr>
{for start='0' end='5' comparsion='lt' name='j' step='1'}
<td>{$j*5+$i}</td>
{/for}
</tr>
{/for}
总结:循环标签有三种语法,各自有不同的用途:volist适合输出格式较复杂的数据,foreach语法简单,适合输出简单数据,for标签适合输出大量重复样式,不适合数据输出,具体要哪个,还要看项目需求~~
网友评论