Re: [SMARTY] function alternate
| From: | Monte Ohrt | Date: | Thu, 02 May 2002 21:15:35 +0000 |
| Subject: | Re: [SMARTY] function alternate | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4010@lists.php.net to get a copy of this message | ||
That's nice, except that the array must then be assigned to the template. In this case, we only know the values to alternate between from within the template. (There is already another thread going on about the ability to assign arrays from within the template, btw.)
I'm leaning toward the idea that alternate should not support more than two values anyways, because then it wouldn't be alternating, would it ;-)
I already added two more attributes:
reset - true/false : resets to val1
print - true/false : whether or not to print ( basically a way to alternate without printing the value so you can skip one )
Monte
G wrote:
How about replace val1 and val2 with "values" which can accept an array? Gerard-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.-----Original Message----- From: Monte Ohrt [mailto:monte@ispi.net] Sent: Thursday, May 02, 2002 2:58 PM To: Smarty Subject: [SMARTY] function alternate I just created a handy function I'd like your input on, called alternate. example: {section ...} <tr><td bgcolor={alternate val1="#eeeeee" val2="#b0b0b0"}> ..... </td></tr> {/section} Each time you call alternate, it will alternate printing val1 and val2. In this example, every cell of the table will alternate background colors. This is kind of a shortcut for something like this: {if $smarty.section.foo.index is even}#eeeeee{else}#b0b0b0{/if} PLUS, if you want to alternate values within one loop of the section (like in the above example), you can do so... it is independent of the current section loop iteration. You can optionally supply a "name" attribute in case you have more than one alternate tag running in the template. So you can do this: {alternate name=foo1 val1="do" val2="re"} {alternate name=foo2 val1="mi" val2="fa"} {alternate name=foo1 val1="do" val2="re"} {alternate name=foo2 val1="mi" val2="fa"} output would be: do mi re fa What I'm wondering, is this syntax good? Are the variable names "val1" and "val2" the best choice? Should the alternate function be able to accomodate three or more values to "alternate" between? Monte -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php