You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by phillip rhodes <rh...@telerama.com> on 2002/09/11 07:37:07 UTC
mod function?
Hi.
When I looping through with a #foreach
I would like to print out some content every 3rd iteration.
While I can do this using variables, etc, I was wondering if there is a velocity elegant way to do this.
Thanks.
Re: mod function?
Posted by Damian Gajda <dg...@ngo.pl>.
> Hi.
> When I looping through with a #foreach
> I would like to print out some content every 3rd iteration.
>
> While I can do this using variables, etc, I was wondering if there is a velocity elegant way to do this.
> Thanks.
It's easy and already available:
#foreach($item in $items)
#set($var = $velocityCount % 3)
$var
#end
BTW. It is always good to read the users guide on velocity site or docs
provided with the distribution. It will certainly save You some time.
Take care,
--
Damian Gajda
Web Application Design and Consultancy
dgajda@ngo.pl
mobile +48 501 032 506
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: mod function?
Posted by Simon Christian <si...@cpd.co.uk>.
Hi Phillip,
There is a mod operator built in:
#foreach( $letter in ["a","b","c","d","e","f","g","h","i","j"] )
#if( $velocityCount % 3 == 0 )$letter #end
#end
Note the $velocityCount variable *may* have been renamed in your
configuration.
HTH
- simon
phillip rhodes wrote:
> Hi.
> When I looping through with a #foreach
> I would like to print out some content every 3rd iteration.
>
> While I can do this using variables, etc, I was wondering if there is a velocity elegant way to do this.
> Thanks.
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>