SMARTY抓住并添加新的clearfix元件制动线

时间:2016-09-26 14:39:43

标签: html loops foreach smarty clearfix

我有代码:

{foreach from=$liconteiners item=lconteiner name=sld}
        <li class="liconteiner col-sm-3">text</li>
{/foreach}

这就是给我这样的东西:

<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>

但我需要在每四个li之后添加另一个li:<li class="clearfix col-lg-12 visible-lg"></li>

所以最后我想要那段代码:

<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="clearfix col-lg-12 visible-lg"></li>
<li class="liconteiner col-sm-3">text</li>

在smarty中可以在foreach循环中添加制动线li元素吗?

修改

当我添加:

{if $smarty.foreach.sld.iteration == 5}
     <li class="clearfix col-lg-12 visible-lg"></li>
{/if}

{if $lconteiner@index eq 4}
    <li class="clearfix col-lg-12 visible-lg"></li>
{/if}

它给了我

<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="clearfix col-lg-12 visible-lg"></li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>

但是当我添加:

{if $lconteiner@iteration is div by 4}
     <li class="clearfix col-lg-12 visible-lg"></li>
{/if}

我给我:

<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="clearfix col-lg-12 visible-lg"></li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="liconteiner col-sm-3">text</li>
<li class="clearfix col-lg-12 visible-lg"></li>
<li class="liconteiner col-sm-3">text</li>

所以这也是错的,我不知道为什么,它应该是每四个元素。

1 个答案:

答案 0 :(得分:0)

已解决,我无法将我的答案标记为已解决。

好的,我知道为什么它不起作用。我在另一个{if}中有它,所以我的问题的解决方案是将其放在外面,如果声明并使用此代码:

{if $lconteiner@iteration is div by 4}
 <li class="clearfix col-lg-12 visible-lg"></li>
{/if}