Something i take for granted in PHP is the use of Modular Arithmetic when display results in a grid like format.
Usually in php, i would do something like this to display three items per row
if ($count % 3 == 0) {
// Add Break / Clear here
}
So i assumed something like this would be available in smarty. After googling for a while i found a couple of solutions to this, however none of them were as simple as the PHP code above, so by playing about with the Smarty Template Engine, i managed to figure out a nice simple way, and here it is.
{assign var="mycount" value="1"} {*Initiate the mycount variable*}
{if $mycount++ % 3 == 0} {*Simular syntax to the above*}
// Add Break / Clear here
{/if}
So, as i found this so useful for displaying products on a current project, i thought it would be something other would really like to know about.

March 24th, 2008 at 5:02 am
[...] Simple Modular Arithmetic with Smarty Template Engine By lotsofcode After googling for a while i found a couple of solutions to this, however none of them were as simple as the PHP code above, so by playing about with the Smarty Template Engine, i managed to figure out a nice simple way, and here it is. … Lots of Code - http://www.lotsofcode.com [...]
September 1st, 2009 at 7:19 pm
Another method is to utilize the "iteration" property of the loop itself. For example:
{foreach from=$records item="r" name="rLoop"}
{if $smarty.foreach.rLoop.iteration % 3 == 0} Break to new row {/if}
{/foreach}