Automatically loop through products and break at certain tr – Pinnacle Cart / Smarty

Using mod + counter in Smarty, you can automatically loop through all of your products, and add a “/tr” to create a new row. I learned of the “counter” option in Smarty, which lets you actually create a counter automatically rather than assigning a variable and incrementing it through the loop.

In this example, I did mod 5 so every 5 products will create a “/tr” in the table. You can change this to however many products you like. I also use thumbnails instead of full pictures, which you can also change.

{counter start=0 direct=up assign="count" print=false}
{if empty($category_level)}
{assign var="category_level" value=1}
{else}
{math equation="x + 1" x=$category_level assign="category_level"}
{/if}

{foreach from=$categories item="category"}
<div></div>
{if $category.level == $category_level &amp;&amp; $category.is_visible == "Yes"}
<div>
<div style="display: none; height: 0;">{$count++}</div>
</div>
<a class="{if !empty($category.children)}parent{/if}" href="{$category.category_url}">{$category.name|htmlspecialchars}
<img style="border: 0px;" src="/images/catalog/thumbs/category{$category.cid}.jpg" alt="" />
</a>
<div>

{math equation="x % 5" x=$count assign="resultcond"}

</div>
<div>

{if $resultcond eq 0}

</div>
{/if}
<div></div>
{/if}
<div>

{/foreach}

</div>
<div>

{math equation="x - 1" x=$category_level assign="category_level"}
{assign var="category" value=0}

</div>

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

munster@mailxu.com