1

基本上这段代码给了我<li>1 2 3 4</li><li>1 2 3 4</li><li>1 2</li>。所以基本上最后我需要将 3 和 4 放入不同的结果,例如 <li>1 2 empty empty</li> - 因为每个 <li></li> 应该总是有 4 个结果,这很棘手,因为循环提供尽可能多的东西,有时甚至更少:)。

<ul>

{section name=attribs loop=$AccountHistory}
   {if $smarty.section.attribs.index % 4 == 0 or $smarty.section.attribs.first}
     <li>
   {/if}

      {$smarty.section.iteration}

   {if $smarty.section.attribs.index % 4 == 3 or $smarty.section.attribs.last}
    </li>
   {/if}

{/section}

</ul>
4

1 回答 1

1

也许像这样进入循环?

{if $smarty.section.attribs.last && ($smarty.section.attribs.index % 4) >0}
   {section name=tmp loop=(4-($smarty.section.attribs.index % 4)) start=(( $smarty.section.attribs.index % 4) + 1)}
      {$smarty.section.tmp.index}
   {/section}
{/if}
于 2013-10-13T19:39:04.357 回答