Smarty 模板:每次迭代打印 2 列
Smarty Template: printing 2 columns in every iteration
我有一个 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}
我有一个 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}