You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Marta Gascó Julio <mg...@care-t.com> on 2006/04/21 16:12:15 UTC

Help with macros

 
Acording to 
 
http://jakarta.apache.org/velocity/docs/user-guide.html <BLOCKED::BLOCKED::http://jakarta.apache.org/velocity/docs/user-guide.html> 
 
It is said about velocimacros: 
Currently, Velocimacros must be defined before they are first used in a template. This means that your #macro() declarations should come before using the Velocimacros. 

This is important to remember if you try to #parse() a template containing inline #macro() directives. Because the #parse() happens at runtime, and the parser decides if a VM-looking element in the template is a VM at parsetime, #parse()-ing a set of VM declarations won't work as expected. To get around this, simply use the velocimacro.library facility to have Velocity load your VMs at startup. 

I'm trying to use a macro defined in one template in other template. I'm doing something similar to the example I explained below. 
 
TemplateA: 
 
#macro ( test )
This is the test macro
#end
 
This is the template A
 
 
TemplateB: 
 
#parse("TemplateA")
The result of calling the macro is:
#test()


 
Then, in my solution C#, I'm adding code in order to modify the Velocity properties indicating the loading of my VMs:
 
Velocity.SetProperty("velocimacro.library", "TemplateA.vm"); 

Velocity.SetProperty("velocimacro.permissions.allow.inline", "false"); 

Velocity.SetProperty("velocimacro.library.autoreload", "true"); 

 
But the result when merge the Template B is: 
 
This is the template A
The result of calling the macro is:
#test()
 
 
While I'm expecting a result like:
This is the template A
The result of calling the macro is:
This is the test macro
 
 
Can you help me with this question? What is happening? Why NVelocity doesn't understand the call to the macro? 
 
I haven't found more information about velocimacros than the user guide and it's not enough.
 
Thanks in advance.




 

Re: Help with macros

Posted by Will Glass-Husain <wg...@forio.com>.
Hi Marta,

You might try the NVelocity mailing list -- it's a separate product based on
Velocity but not actively used by most readers of this list.

Good luck!

WILL

On 4/21/06, Marta Gascó Julio <mg...@care-t.com> wrote:
>
>
> Acording to
>
> http://jakarta.apache.org/velocity/docs/user-guide.html<BLOCKED::BLOCKED::
> http://jakarta.apache.org/velocity/docs/user-guide.html>
>
> It is said about velocimacros:
> Currently, Velocimacros must be defined before they are first used in a
> template. This means that your #macro() declarations should come before
> using the Velocimacros.
>
> This is important to remember if you try to #parse() a template containing
> inline #macro() directives. Because the #parse() happens at runtime, and the
> parser decides if a VM-looking element in the template is a VM at parsetime,
> #parse()-ing a set of VM declarations won't work as expected. To get around
> this, simply use the velocimacro.library facility to have Velocity load
> your VMs at startup.
>
> I'm trying to use a macro defined in one template in other template. I'm
> doing something similar to the example I explained below.
>
> TemplateA:
>
> #macro ( test )
> This is the test macro
> #end
>
> This is the template A
>
>
> TemplateB:
>
> #parse("TemplateA")
> The result of calling the macro is:
> #test()
>
>
>
> Then, in my solution C#, I'm adding code in order to modify the Velocity
> properties indicating the loading of my VMs:
>
> Velocity.SetProperty("velocimacro.library", "TemplateA.vm");
>
> Velocity.SetProperty("velocimacro.permissions.allow.inline", "false");
>
> Velocity.SetProperty("velocimacro.library.autoreload", "true");
>
>
> But the result when merge the Template B is:
>
> This is the template A
> The result of calling the macro is:
> #test()
>
>
> While I'm expecting a result like:
> This is the template A
> The result of calling the macro is:
> This is the test macro
>
>
> Can you help me with this question? What is happening? Why NVelocity
> doesn't understand the call to the macro?
>
> I haven't found more information about velocimacros than the user guide
> and it's not enough.
>
> Thanks in advance.
>
>
>
>
>
>
>


--
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com