smarty如何嵌套循环?本文主要介绍了smarty的section嵌套循环用法,结合简单实例形式分析了smarty使用section进行嵌套循环操作的实现技巧,需要的朋友可以参考下。希望对大家有所帮助。
具体如下:
{section name="sec1" loop=$typelist}
<table class=left20 height=25 cellspacing=0 cellpadding=0 width=624
background=images/indexbg.gif border=0>
<tbody>
<tr>
<td class=zi align=left width=554 height=25> <font
color=#ffffff><b>{$typelist[sec1].typename}</b></font></td>
<td valign=top width=70 height=25><a href="hot.html"><img src="images/more.gif" width="53" height="25"
border=0></a></td>
</tr></tbody></table>
<table cellspacing="0" cellpadding="0">
<tr>
{section name="sec2" loop=$typelist[sec1].shop}
<td><table cellspacing="0" cellpadding="0">
<tr>
<td valign="center" align="middle" width="116"><table cellspacing="0" cellpadding="0">
<tr>
<td><a href="show_prop.php?id={$typelist[sec1].shop[sec2].id}" target="_blank"><img src="http://localhost/{$typelist[sec1].shop[sec2].img_url}" width="84" height="88" border="0"></a></td>
</tr>
</table></td>
</tr>
<tr>
<td class="hongzi" align="middle"> <a href="a01.htm">{$typelist[sec1].shop[sec2].name} </a> </td>
</tr>
<tr>
<td class="zi2" align="middle">数量:{$typelist[sec1].shop[sec2].num} 个 </td>
</tr>
<tr>
<td class="zi2" align="middle">价格:{$typelist[sec1].shop[sec2].price} 白金币 </td>
</tr>
</table></td>
{/section}
</tr>
</table>
{/section}
将sec1 的 $typelist[sec1].shop 作为sec2的loop
就可以取到shop其中的数组的内容
相关推荐:
smarty模板如何使用变量调节器
smarty如何生成简单的表单元素
smarty模板引擎如何进行缓存的机制详解
以上就是smarty如何嵌套循环的详细内容。