PHP smarty中section的一个问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 05:40:16
<html>
<head><title>模板中的流程控制</title><head>
<body>
<table border="1" align="center">
{assign var="tbColor" value="green"}
色彩:{$tbColor}<br>
{section name=loop loop=$News}
{if $tbColor == "green"}
<tr bgcolor="{$tbColor}">
{assign var="tbColor" value="orange"}
{else $tbColor == "orange"}
<tr bgcolor = "{$tbColor}">
{assign var="tbColor" value="green"}
{/if}
<td>{"............"}</td>
<td>{$News[loop].newsID}</td>
<td>{$News[loop].newsTitle}</td>
<tr>
{/section}
</table>
</body>
</html>
这个,想在..........那个位置输出index(0,1,2,3..),该怎么写?

$smarty.section.loop(这里写的是你section设的name).index

index是从0开始

$smarty.section.loop(这里写的是你section设的name).iteration

iteration是从1开始

$smarty.section.loop(这里写的是你section设的name).rownum

rownum是iteration的别名

附一个例子;
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}<br/>
{/section}

OUTPUT:

0 id: 1000<br>
1 id: 1001<br>
2 id: 1002<br>