Smarty module?

I am in a cycle to display products ...

4 per line, unlimited lines

I need to know if this is the nth record ... an example every 4 elements ... Therefore, I know its first column, as in paragraph 1, paragraph 5, paragraph 9, etc. .... Or the last element of paragraph 4 paragraph 8 paragraph 12

Tried these where

{foreach from=$sproducts item="product" name="sproducts"}
{counter assign="bobis" name="bobis"  }

{if $bobis is  div by 4|| $laster ==1}
{if $bobis mod 4 == 0}

 {if $bobis !=4 && $bobis !=8 && $bobis != 12}

Any easy way?

+3
source share
2 answers

If I understand the question correctly, just put the class col-in your element:

<div class="col-{$bobis mod 4}">...</div>

You should get the following:

<div class="col-1">...</div>
<div class="col-2">...</div>
<div class="col-3">...</div>
<div class="col-4">...</div>
<div class="col-1">...</div>
<div class="col-2">...</div>

... etc.

+5
source

, , script. . , , .

<table>
{foreach from=$sproducts item="product" name="sproducts"}
{if $product@first}<tr>{/if}
<td>{$product}</td>
{if $product@last}</tr>
{else}{if $product@iteration is div by 4}</tr><tr>
{/if}
{/if}
{/foreach}
</table>
+1

All Articles