Monday 24th March 2008Simple Modular Arithmetic with Smarty Template Engine
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.
[...] 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 [...]
March 24th, 2008 at 5:02 am