function alternate
| From: | Monte Ohrt | Date: | Thu, 02 May 2002 20:58:09 +0000 |
| Subject: | function alternate | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-4006@lists.php.net to get a copy of this message | ||
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