在foreach中加入 key=count
<{foreach item=item from=$items key=count}>
<{if $count is div by 2}>
<{/if}>
<{$item.name}> |
<{$item.summary}> |
<{$item.date}> |
<{if ($count+1) is div by 2}>
<{/if}>
<{/foreach}>
每行放置三个 <{$item.name}> 后换行 你喜欢换多少就改改参数就可以了!
<{foreach item=item from=$items key=count}>
<{$item.name}> |
<{if ($count+1) is div by 3}>
<{/if}>
<{/foreach}>
另一种利用 cycle 來做换行的例子,但只能作到每行两条数据就换行的效果 只能换两行
<{foreach item=item from=$items}>
<{$item.name}> <{cycle values=" | ,
"}>
<{/foreach}>