当前位置:首页> PHP教程> php模板
关键字
文章内容
smarty 換行範例
 
 
修改时间:[2012/02/20 05:58]    阅读次数:[2738]    发表者:[起缘]
 
在 foreach 中加入 key=count

<table>  
<{foreach item=item from=$items key=count}>  
<{if $count is div by 2}><tr>
<{/if}>   
<td><{$item.name}></td>   
<td><{$item.summary}></td>   
<td><{$item.date}></td>  
<{if ($count+1) is div by 2}></tr><{/if}>  
<{/foreach}></table>

每行放置三個 <{$item.name}> 後換行

<table>  
<tr>  
<{foreach item=item from=$items key=count}>      
<td><{$item.name}></td>  
<{if ($count+1) is div by 3}></tr><tr><{/if}>  
<{/foreach}>  
</tr></table>

另一種利用 cycle 來做換行的例子,但只能作到每行兩筆資料就換行的效果

<table>  
<tr>   
<{foreach item=item from=$items}>      
<td><{$item.name}>      
<{cycle values="</td>,</td></tr><tr>"}>   
<{/foreach}>  
</tr>
</table>