You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Robert Brandner <ro...@chello.at> on 2004/08/22 18:10:56 UTC

Unset variables?

Hi!

Isn't there a possibility to unset a variable (or set it to null)?

Given the following macro 'demo' and 2 objects o1 with action==null and 
o2 with action != null.

#macro(demo $object)
   #set($action = $object.action)
   #if($action)
     ## do something
   #end
#end

Now, when I call #demo($o1) the variable $action is not set and the 
macro does nothing - as expected.

Now, I call #demo($o2) $action gets set (as o2 has an action) and the 
macro 'does something' - as expected.

But when I call #demo($o1) again, $action stays set (even though 
o1.action == null) and the macro does something?! Strange!

And a second question: Is there a possibility to have 'local' variables 
within a macro? I suppose not -- I guess I think of a macro as a 
function but that's not the case, right?

Best regards

Robert



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


Re: Unset variables?

Posted by Kishore Senji <ks...@gmail.com>.
> #macro(demo $object)
>   #set($action = $object.action)
>   #if($action)
>     ## do something
>   #end
> #end

You have to set $action = false.

 #macro(demo $object)
   #set($action = false)
   #set($action = $object.action)
   #if($action)
     ## do something
   #end
 #end

Thanks,
Kishore Senji

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