velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason St. Louis" <>
Subject determining odd/even position in foreach loop
Date Sun, 20 Jun 2004 07:42:19 GMT
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" )
		#set ( $row_class = "red" )

I guess I could do it like this?

#if ( $velocityCount%2 == 0 )
	#set ( $row_class = "blue" )
	#set ( $row_class = "red" )

But is that the best way?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message