本文实例讲述了smarty表格换行的实现方法。分享给大家供大家参考。具体分析如下:
在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>