每第n次Smarty新表行

时间:2014-07-24 17:54:58

标签: 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 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个元素之后它创建了这个分页符,所以我想要的是当我让每个6个元素分别拥有自己的表格内的表格时。

1 个答案:

答案 0 :(得分:0)

以下代码适合您:

<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>

但由于很多桌子我无法确定。您还可以查看Break UL tag after 'n' times in while-loop,我在PHP中回答了如何做同样的事情。

相关问题