Re: New looping method proposal

From: Date: Sun, 18 Nov 2001 19:52:19 +0000
Subject: Re: New looping method proposal
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1941@lists.php.net to get a copy of this message
This is only good for looping through one variable. More times than not, there are several variables you want to access from within the loop. Ivo Jansch wrote: > Hello, > > one of the things that is hardest to understand for the template editors > in our company is the looping functionality. > > The {section name= loop=} syntax is quite usable once you get the hang > of it, but when you're new, it's not easy. The reason is probably that > it's so unlike any other looping mechanism in programming languages. > > I was thinking of a simpler alternative, inspired by one of php's own > looping mechanism: > > {foreach $persons as $person} > <br>{$person.name} > {/for} > > I think that for maybe 9 out of 10 loops, this would suffice. If you > need to access the index, than you could use the {section} way of > looping, or, you could do: > > {foreach $persons as $i => $person} > {if $i % 2 == 0} +{$person.name} > {else} -{$person.name} > {/if} > {/for} > > This is also equivalent to php's looping, so parsing this should not be > too hard. > > What do you think of this? > > Greetings, > Ivo > > -- > Ivo Jansch <ivo@ibuildings.nl> > ibuildings.nl BV - information technology > http://www.ibuildings.nl > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/

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