velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Glass-Husain" <wgl...@forio.com>
Subject Re: determining odd/even position in foreach loop
Date Mon, 21 Jun 2004 05:31:39 GMT
Didn't we have a big discussion about this in the list earlier in the year?
I couldn't find the message.  I seem to remember the Velocity Tools people
coming up with something clever.

I like the macro idea though.

WILL

----- Original Message ----- 
From: <Martin.Rademacher@prg.co.nz>
To: "Velocity Users List" <velocity-user@jakarta.apache.org>
Sent: Sunday, June 20, 2004 9:42 PM
Subject: Re: determining odd/even position in foreach loop


> You could use a #macro.
>
> For example something like:
>
> #macro( isOdd $number $oddText $evenText )#if( 0 == $number%2
> )$evenText#else$oddText#end#end
>
> And the in your loop something like:
>
> #foreach ($foo in $bar)
>         <tr class="#isOdd( $velocityCount "blue" "red" )">
>                 ...
>         </tr>
> #end
>
> mano
>
>
>
>
> "Jason St. Louis" <jason.stlouis@gravitybound.net>
> 20/06/2004 19:42
> Please respond to
> "Velocity Users List" <velocity-user@jakarta.apache.org>
>
>
> To
> velocity-user@jakarta.apache.org
> cc
>
> Subject
> determining odd/even position in foreach loop
>
>
>
>
>
>
> Hi everyone.
>
> Is there a built in way of determining whether the current iteration you
> are on is even or odd in a foreach loop?
>
> I am using alternating colors to display rows in a table more visibly
> and I was just hoping there was some easy way of doing this in velocity,
> something like:
>
> #foreach ($foo in $bar)
>                  #if ( $velocity-even )
>                                  #set ( $row_class = "blue" )
>                  #else
>                                  #set ( $row_class = "red" )
>                  #end
> #end
>
> I guess I could do it like this?
>
> #if ( $velocityCount%2 == 0 )
>                  #set ( $row_class = "blue" )
> #else
>                  #set ( $row_class = "red" )
> #end
>
>
> But is that the best way?
>
> Thanks!
> Jason
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message