velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Townson, Chris" <C.Town...@nature.com>
Subject finding the length of an array
Date Thu, 18 Aug 2005 13:05:46 GMT
after reading through Jean Francois Chamard's excellent technique for
finding the last item in an array with Velocity (posted 22/07/2005), I've
been trying to implement this for a array of HTML links.

however, I've been encountering problems using the length method which is
used there: it's just failing silently (haven't got access to the velocity
log for this at present, unfortunately).

here is the code I am using:

## a load of links, with text + hrefs etc held in their own array
#set ( $link1 = ["link 1","this is link one","http://link.one"] )
#set ( $link2 = ["link 2","this is link two","http://link.two"] )
#set ( $link3 = ["link 3","this is link three","http://link.three"] )
#set ( $link4 = ["link 4","this is link four","http://link.four"] )
#set ( $link5 = ["link 5","this is link five","http://link.five"] )
#set ( $link6 = ["link 6","this is link six","http://link.six"] )

## stick alll those arrays into an array
#set ( $linkMultiArray = [$link1,$link2,$link3,$link4,$link5,$link6] )

## do loop to produce output
#set( $len = $linkMultiArray.length )
#foreach($link in $linkMultiArray)
    #set( $velocityCount2 = $velocityCount + 1 )
    #set( $len2 = $len - 1 )
    $link.get(0)#if($len2 == $velocityCount) and#elseif($len >
$velocityCount2), #end
#end

the desired result:
link 1, link 2, link 3, link 4, link 5 and link 6

what I'm getting:
link 1link 2link 3link 4link 5link 6

Any comments/suggestions/help/answers gratefully received!

thanks,

Chris

********************************************************************************   
DISCLAIMER: This e-mail is confidential and should not be used by anyone who is
not the original intended recipient. If you have received this e-mail in error
please inform the sender and delete it from your mailbox or any other storage
mechanism. Neither Macmillan Publishers Limited nor any of its agents accept
liability for any statements made which are clearly the sender's own and not
expressly made on behalf of Macmillan Publishers Limited or one of its agents.
Please note that neither Macmillan Publishers Limited nor any of its agents
accept any responsibility for viruses that may be contained in this e-mail or
its attachments and it is your responsibility to scan the e-mail and 
attachments (if any). No contracts may be concluded on behalf of Macmillan 
Publishers Limited or its agents by means of e-mail communication. Macmillan 
Publishers Limited Registered in England and Wales with registered number 785998 
Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS   
********************************************************************************
Mime
View raw message