开发者

Smarty modulus?

I'm in a loop to display products...

4 per row, unlimited rows'

I need to know if it's the nth entry... example every 4 items... So I know its the first column as in item 1, item5, item 9 etc... Or last item item 4, item 8, item 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 simple way?


If I understand the question right, just put a col- class on your item:

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

...and so on


If you are using tables this is something I pulled from a script I am currently working on and adapted to your code somewhat. You probably would have to make some changes but it somewhat gives you an idea.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜