本文實例講述了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模板入門基礎教程》、《PHP模板技術總結》、《PHP基於pdo操作數據庫技巧總結》、《PHP運算與運算符用法總結》、《PHP網絡編程技巧總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
希望本文所述對大家基於smarty模板的PHP程序設計有所幫助。