Agnes Tom Agnes Tom - 2 months ago 7
Smarty Question

SMARTY forach and adding new clearfix element braking lines

I have code:

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


and this is give me something like this:

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


but I need to add after every four li another li:
<li class="clearfix col-lg-12 visible-lg"></li>


so finally I want that code:

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


It is possible in smarty to add braking line li element in the foreach loop?

EDIT.

When I add:

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


or

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


it give me

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


But when I add:

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


I give my:

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


So this is also wrong, and I don't know why, it supposed to be by every fourth element.

Answer

SOLVED, I cant mark my answer as solved.

Ok, I know why it was not work. I have it in another {if}, so solution from my problem was put it outside if statment and use this code:

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