You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "White, Joshua A (HTSC, CASD)" <Jo...@thehartford.com> on 2004/01/28 14:53:09 UTC

Special logic for last iteration of collection

Hello everyone,
 
I am just starting with velocity.  I am trying to generate a comma delimited
list (method arguments) and would like it to appear like this:
 
(item1, item2, item3)
 
I can't figure out how to not add a comma if we are on the last element of
our list.  Could someone help me out?
 
Regards,
 
Joshua


This communication, including attachments, is for the exclusive use of 
addressee and may contain proprietary, confidential or privileged 
information. If you are not the intended recipient, any use, copying, 
disclosure, dissemination or distribution is strictly prohibited. If 
you are not the intended recipient, please notify the sender 
immediately by return email and delete this communication and destroy all copies.


Re: Special logic for last iteration of collection

Posted by Samuel Le Berrigaud <le...@essi.fr>.
Hi Joshua,

you may use the $velocityCount == $list.size() or $list.size() + 1 to 
figure out when you are on the last element, depending on the start 
value of $velocityCount

Regards,

SaM


White, Joshua A (HTSC, CASD) wrote:

>Hello everyone,
> 
>I am just starting with velocity.  I am trying to generate a comma delimited
>list (method arguments) and would like it to appear like this:
> 
>(item1, item2, item3)
> 
>I can't figure out how to not add a comma if we are on the last element of
>our list.  Could someone help me out?
> 
>Regards,
> 
>Joshua
>
>
>This communication, including attachments, is for the exclusive use of 
>addressee and may contain proprietary, confidential or privileged 
>information. If you are not the intended recipient, any use, copying, 
>disclosure, dissemination or distribution is strictly prohibited. If 
>you are not the intended recipient, please notify the sender 
>immediately by return email and delete this communication and destroy all copies.
>
>
>  
>

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


Re: Special logic for last iteration of collection

Posted by Barbara Baughman <ba...@utdallas.edu>.
Try

(#foreach($element in $list)$element#if($velocityCount==list.size()))#else,#end

Starts with a (, then the element followed by a comma if we're not on
the last element, followed by a ) if this is the last element.

Barbara Baughman
X2157

On Wed, 28 Jan 2004, White, Joshua A (HTSC, CASD) wrote:

> Hello everyone,
>
> I am just starting with velocity.  I am trying to generate a comma delimited
> list (method arguments) and would like it to appear like this:
>
> (item1, item2, item3)
>
> I can't figure out how to not add a comma if we are on the last element of
> our list.  Could someone help me out?
>
> Regards,
>
> Joshua
>
>
> This communication, including attachments, is for the exclusive use of
> addressee and may contain proprietary, confidential or privileged
> information. If you are not the intended recipient, any use, copying,
> disclosure, dissemination or distribution is strictly prohibited. If
> you are not the intended recipient, please notify the sender
> immediately by return email and delete this communication and destroy all copies.
>
>

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


Re: Special logic for last iteration of collection

Posted by Christoph Reck <ap...@recks.org>.
Avoid the stated $velocityCount reference, just do:

#set( $sep  = "" )
(#foreach( $param in $parmlist )$sep$param#set( $sep = ", " )#end)

Hope this helps,
Christoph


White, Joshua A (HTSC, CASD) wrote:
> Hello everyone,
>  
> I am just starting with velocity.  I am trying to generate a comma delimited
> list (method arguments) and would like it to appear like this:
>  
> (item1, item2, item3)
>  
> I can't figure out how to not add a comma if we are on the last element of
> our list.  Could someone help me out?
>  
> Regards,
>  
> Joshua


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