Php 每N次Smarty新表行

Php 每N次Smarty新表行,php,iteration,smarty,Php,Iteration,Smarty,您好,我正在制作这封HTML电子邮件,感谢旧的Outlook 07,它增加了一个非常好的分页符,我有点不得不改变我的逻辑。目前,我的html看起来像这样: <table> <tr> //I want for every 6th element to create a new <tr> <td> <table> {foreach from=$data.elements item=element n

您好,我正在制作这封HTML电子邮件,感谢旧的Outlook 07,它增加了一个非常好的分页符,我有点不得不改变我的逻辑。目前,我的html看起来像这样:

<table>
  <tr>  //I want for every 6th element to create a new <tr>
    <td>
      <table>
        {foreach from=$data.elements item=element name=elements}
        {if $smarty.foreach.elements.iteration is odd}
        <tr>
          <td>
        {/if}
            <table align="{if $smarty.foreach.elements.iteration is odd}left{else}right{/if}">
                Some content
            </table>
          {if $smarty.foreach.elements.iteration is odd}
            <table align="left" cellspacing="0" cellpadding="0">
               <tr>
                  <td width="100%" height="40" style="font-size:1px; line-height:1px; mso-line-height-rule: exactly;">&nbsp;</td>
               </tr>
            </table>
          {else}
                  </td>
               </tr>
          {/if}
          {/foreach}
      </table>
    </td>
  </tr>
</table>

现在,在第6个元素之后,它创建了这个分页符,所以我想要的是,当我有12个元素时,每6个元素都有自己的表行,其中包含表。

以下代码应该适用于您:

<table>

        {foreach from=$data.elements item=element name=elements}
        {if $smarty.foreach.elements.iteration mod 6 eq 1}
            <tr>  
            <td>
                <table>
        {/if}        

        {if $smarty.foreach.elements.iteration is odd}
        <tr>
          <td>
        {/if}
            <table align="{if $smarty.foreach.elements.iteration is odd}left{else}right{/if}">
                Some content
            </table>
          {if $smarty.foreach.elements.iteration is odd}
            <table align="left" cellspacing="0" cellpadding="0">
               <tr>
                  <td width="100%" height="40" style="font-size:1px; line-height:1px; mso-line-height-rule: exactly;">&nbsp;</td>
               </tr>
            </table>
          {else}
                  </td>
               </tr>
          {/if}
          {if $smarty.foreach.elements.iteration mod 6 eq 0 or $smarty.foreach.elements.last}
               </table>
            </td>
          </tr>
        {/if}          
          {/foreach}

</table>

但是因为有很多表格,我不能确定地检查它。你也可以看看我在哪里回答了如何在PHP中实现同样的功能。

非常感谢你,伙计,你太棒了: