Re: Splitting rows with Smarty

From: Date: Wed, 18 Dec 2002 15:41:30 +0000
Subject: Re: Splitting rows with Smarty
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6876@lists.php.net to get a copy of this message
Sorry for the empty posting ;-) <table> <tr> {* begin of first row *} {foreach from=$images item=image key=index} {if ($index is div by $rowSplit) && ($index > 0) } {* add a new row *} </tr> <tr> {/if} {* OK, the part with the opening TR tag works *} {* but what to do with the closing tag? *} {* display cells with TD *} {/foreach} </tr> {* end of last row *} </table> This should work I think (not tested yet). But consider the following two things: 1) If $images is an empty array foreach won't output anything. Your table will look like this: <table><tr></tr></table> So you should use {foreach} ... {foreachelse}<td>Nothing to display</td> {/foreach} 2) If the array index of $images is 0..n you can use a {section} instead of {foreach}. Then you have some special variables available: {$smarty.section.index.rownum} {$smarty.section.index.first} {$smarty.section.index.last} {$smarty.section.index.index_prev} {$smarty.section.index.index_next} This can make life a lot easier ;-) André "André Rabold" <arabold@nero.com> schrieb im Newsbeitrag news:20021218153249.23407.qmail@pb1.pair.com... > > > > > "Radu-Mihail Obada" <radu@fmi.unibuc.ro> schrieb im Newsbeitrag > news:20021218145251.GB14279@fmi.unibuc.ro... > > Hi, > > Say I have two variables avaiable in my Smarty template, let them be > > called $rowSplit and $images. I want to display the things stored in > > $images (which is an array) in a table, but I want the table to have no > > more than $rowSplit columns per row. And the question is: is there a way > > to achieve this in _the template_ code? For example, is it possible to do > > something like: > > {* this is not valid Smarty code *} > > <table> > > {foreach from=$images item=image key=index} > > {if $index is div by $rowSplit} > > <tr> > > {/if} > > {* OK, the part with the opening TR tag works *} > > {* but what to do with the closing tag? *} > > > > {* display cells with TD *} > > > > {if $index % $rowSplit eq $rowSplit -1} {* This doesn't work *} > > </tr> > > {/if} > > {/foreach} > > </table> > > ? > > > > Thanks in advance, > > Radu > > > >

« previous php.smarty.general (#6876) next »