velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dan Bachelder" <cho...@chowda.net>
Subject Re: #set silently fails if RHS is null
Date Thu, 08 Nov 2001 03:45:59 GMT
will this work for you...

#if($item.colour) $color #end


----- Original Message -----
From: "Mike Williams" <mikew@cortexebusiness.com.au>
To: <velocity-user@jakarta.apache.org>
Sent: Wednesday, November 07, 2001 10:41 PM
Subject: #set silently fails if RHS is null


> 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?
>
> --
> cheers, Mike
>
>
> --
> To unsubscribe, e-mail:
<mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:velocity-user-help@jakarta.apache.org>
>
>


--
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