velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason St. Louis" <jason.stlo...@gravitybound.net>
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" )
	#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


Mime
View raw message