Re: section step

From: Date: Tue, 27 Nov 2001 16:30:46 +0000
Subject: Re: section step
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2054@lists.php.net to get a copy of this message
On Tue, 27 Nov 2001, Rod K wrote: > On to my problem. Maybe I'm missing something in the manual, but I have the > following problem. I want to step thru an array by 4 so I end up with four > columns in the table. My question is, how do I accomplish the modification > of the index to reference the 2nd, 3rd and 4th indices? > > <code> > > {section name=sec1 loop=$links step=4} > <tr height=35 bgcolor="{if %sec1.iteration% is > even}#cccccc{else}#ffffff{/if}"> > <td align=center width=25%><a > href="{$links[sec1]}">{$makes[sec1]}</a></td> > <td align=center width=25%><a > href="{$links[???]}">{$makes[???]}</a></td> > <td align=center width=25%><a > href="{$links[???]}">{$makes[???]}</a></td> > <td align=center width=25%><a > href="{$links[???]}">{$makes[???]}</a></td> > </tr> > {/section} > > </code> Don't do it like this. Instead loop through the section without 'step' attribute at all, and use {if ..} tags to check when you need to start/end row. Something like: {section name=sec1 loop=$links} {if %sec1.first%} <tr height=35 bgcolor="{if %sec1.index% is even by 4}#cccccc{else}#ffffff{/if}"> {/if} <td align=center width=25%><a href="{$links[sec1]}">{$makes[sec1]}</a></td> {if %sec1.index% is div by 4} </tr> <tr height=35 bgcolor="{if %sec1.iteration% is even}#cccccc{else}#ffffff{/if}"> {/if} {if %sec1.last%} </tr> {/if} {/section} -Andrei "Someone clearly thinks that C is a garbage collected language" -- Morten Welinder

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