[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Re: Macro as an argument to a macro
From:       Simon Bates <simon.bates () utoronto ! ca>
Date:       2004-06-28 18:21:29
Message-ID: 40E061A9.6010801 () utoronto ! ca
[Download RAW message or body]

Simon Bates wrote:
> I would like to pass a macro as an argument to another macro. I have 
> read the question in the Velocity user documentation "Can I use a 
> directive or another VM as an argument to a VM?" However, I do not seem 
> to be getting the behaviour described. It looks like directives are not 
> being evaluated for me in quoted (") arguments to macros. Any guidance 
> would be greatly appreciated.

I have now carried out some more testing and experimentation. If I place 
the macros below in a library that is loaded at startup then macro 
directives calling them are evaluated in quoted strings as arguments to 
other macros. However, if the macros are specified inline I believe they 
are not evaluated.

Best wishes,
Simon

> When I try the example in the documentation:
> 
> #macro( inner $foo )
>   inner : $foo
> #end
> 
> #macro( outer $foo )
>    #set($bar = "outerlala")
>    outer : $foo
> #end
> 
> #set($bar = 'calltimelala')
> #outer( "#inner($bar)" )
> 
> I get "outer : #inner(outerlala)" rather than "outer : inner : outerlala".
> 
> And given:
> 
> #macro(m1)
> Hello World
> #end
> 
> #macro(echo $arg)
> $arg
> #end
> 
> If I use the following:
> 
> #echo("#m1()")
> 
> I get "#m1()" but the directive is evaluated if I use this:
> 
> #set($foo = "#m1()")
> #echo($foo)
> 
> I get "Hello World".
> 
> I tested in Velocity 1.4.
> 
> Thanks very much for your help. Best wishes,
> Simon


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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic