【问题标题】:How add new line after four looping in smarty templates如何在 smarty 模板中循环四次后添加新行
【发布时间】:2015-05-14 00:05:01
【问题描述】:

我想在四次循环后添加新行。我使用 {section loop=$arrProducts name=index} 当执行数组将在一行中显示所有产品但我想每四个产品添加一行。我该怎么办???

感谢我使用的这段代码

{if $arrProducts neq " "}
{section loop=$arrProducts name=index}
<td width="565" align="center" valign="top">

<img src="admin/{$arrProducts[index].image}" width="121" height="90" class="prodImg"/><br>
<span class="prodName">{$arrProducts[index].name}</span><br>
<span class="prodPrice">{$arrProducts[index].price}&nbsp;LE</span><br>
<font class="quality">QTY.</font><input type="text" name="txtorder" size="1" class="txtproduct" /><font class="quality">&nbsp;Kg</font><br />
</td>
{/section}
{/if}

【问题讨论】:

    标签: php smarty


    【解决方案1】:

    我总是使用 smarty 数学来查看是否必须添加新行。它可能看起来像这样:

    {if $arrProducts neq " "}
    <tr>
    {section loop=$arrProducts name=index}
    {if $index % 4 == 0}
    </tr><tr>
    {/if}
    <td width="565" align="center" valign="top">
    
        <img src="admin/{$arrProducts[index].image}" width="121" height="90" class="prodImg"/><br>
        <span class="prodName">{$arrProducts[index].name}</span><br>
        <span class="prodPrice">{$arrProducts[index].price}&nbsp;LE</span><br>
        <font class="quality">QTY.</font><input type="text" name="txtorder" size="1" class="txtproduct" /><font class="quality">&nbsp;Kg</font><br />
    </td>
    {/section}
    </tr>
    {/if}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2012-06-19
      • 2013-06-30
      • 2018-10-26
      相关资源
      最近更新 更多