New looping method proposal
| From: | Ivo Jansch | Date: | Sun, 18 Nov 2001 11:21:16 +0000 |
| Subject: | New looping method proposal | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-1940@lists.php.net to get a copy of this message | ||
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