我有一个php脚本,用于填充和辅助我的smarty数组。我想在一行中打印两列,然后开始另一行。
{section name=customer loop=$custid}
<tr>
// would love to start another loop here which will loop two times
<td>$custid<td>
// and end loop here
</tr>
{/section}
您可以将mod运算符与当前循环索引一起使用,类似这样的操作(未测试)可能会起作用:
{section name=customer loop=$custid}
{assign var="column" value=$smarty.section.customer.index%2}
{if $column==0}<tr>{/if}
<td>$custid<td>
{if $column==1 || $smarty.section.customer.last}</tr>{/if}
{/section}