how about using the velocity built-in alternator:
http://jakarta.apache.org/velocity/api/org/apache/velocity/app/tools/VelocityFormatter.html#makeAutoAlternator(java.lang.String,%20java.lang.String,%20java.lang.String)
If you are using the VelocityViewServlet from the velocity-tools subproject, you just configure it to be available to the web designer and voil�, you are wired for sound, ahem, colors!
<table>
$formatter.makeAutoAlternator("rowcolor", "#c0c0c0", "#e0e0e0")
#foreach $item in $items
#begin
<tr><td bgcolor="$rowcolor">$item.Name</td></tr>
#end
</table>No need for a new directive - just a tool!
Maybe we should be shifting these tools over to velocity-tools/generic?
Cheers, Christoph
evik wrote:
Hi!
I usually print my tables that have every other row a little different color for easier reading. I did not find any such thing dirrectly supported in velocity so I made a little patch. It extends foreach like this: #foreach ( $item in $list ["#aaaaaa", "#eeeeee"] as $color ) <tr bgcolor="$color"> <td>$item</td> </tr> #end
It will render every odd row with bgcolor="#aaaaaa" and the
even ones with bgcolor="#eeeeee". I thinkahelps to the designer or the developper who had to solve this issue
with macro logic.
If anyone is interested I put up a patch against the current CVS version at: http://chaos.hu/foreach_cycle.patch.gz
I wrote it if the ( $item in $list ) paramters are correct, and
the cycling parameters have any problem, the code will not drop
any errors, but render like if only the first two args would be
given. This is for not rendering a page useless because someone
tinkered around he cycling list. Also note that this logic makes
the extended parameters optional, so the old style works just as
it should.
Also I "discovered" a rendering problem during this development. If anyone accidentally gives another parameter to #foreach, the render code would threat the fourth parameter as the rendering template. This patch also fix this by not rendering to a fix numbered child but always to invoke rendering on the last child.
Any feedback is appreciated.
evik
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
