velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: #set silently fails if RHS is null
Date Thu, 08 Nov 2001 03:46:37 GMT
On 11/7/01 10:41 PM, "Mike Williams" <mikew@cortexebusiness.com.au> wrote:

> I have a loop that looks something like this:
> 
>   #foreach( $item in $items )
>   #set( $colour = $item.colour )
>   #if( $colour ) {
>       A $colour ${item.name}
>   #end
>   #end
> 
> Now say I have the following list of items:
> 
>   #1 name="hammer"
>   #2 name="wheelbarrow" colour="blue"
>   #3 name="wheelbarrow" colour="red"
>   #4 name="screwdriver"
> 
> I expected the output to be
> 
>   A blue wheelbarrow
>   A red wheelbarrow
> 
> But, in fact it's
> 
>   A blue wheelbarrow
>   A red wheelbarrow
>   A red screwdriver
> 
> The problem is that Velocity skips the #set if the RHS is null (well, this
> is what the logs tell me).  This seems to be pretty counter-intuitive
> behaviour ... is there a reason for it?  What's the best work-around?

The logs donĀ¹t lie.

How about

#foreach( $item in $items )
  #if( $item.color)
     A $item.color $item.name
  #end
#end

?


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



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


Mime
View raw message