velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Williams <>
Subject #set silently fails if RHS is null
Date Thu, 08 Nov 2001 03:41:53 GMT
I have a loop that looks something like this:

    #foreach( $item in $items )
    #set( $colour = $item.colour )
    #if( $colour ) {
        A $colour ${}

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:   <>
For additional commands, e-mail: <>

View raw message