You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Colbert Philippe <co...@rogers.com> on 2006/07/02 06:37:05 UTC
How can I define a macro in different file and use it?
I tried to define a simple macro in one file and using it in another macro file. I attempted to do this using #parse. This is an important functionality for programmers.
Defining a simpel macro in macrolibrary.vm
## This macro simply prints its 3 parameters separated by single space
#macro( myMacro $p1 $p2 $p3 )
$p1 $p2 $p3
#end
Using it in separate file usingmymacro.vm
#parse( "macrolibrary.vm" )
#myMacro( "alpha" "beta" "gamma" )
Output of running Velocity with my file usingmymacro.vm
#myMacro( "alpha" "beta" "gamma" )
It's as if it does not recognize the difinition of the macro that it parsed. Has somebody ran into this problem?
Re: How can I define a macro in different file and use it?
Posted by Markus Reinhardt <mr...@hygiene.uni-wuerzburg.de>.
Velocity Manual:
Colbert Philippe wrote:
> I tried to define a simple macro in one file and using it in another macro file. I attempted to do this using #parse. This is an important functionality for programmers.
>
> Defining a simpel macro in macrolibrary.vm
> ## This macro simply prints its 3 parameters separated by single space
> #macro( myMacro $p1 $p2 $p3 )
> $p1 $p2 $p3
> #end
>
> Using it in separate file usingmymacro.vm
>
> #parse( "macrolibrary.vm" )
>
> #myMacro( "alpha" "beta" "gamma" )
>
> Output of running Velocity with my file usingmymacro.vm
>
> #myMacro( "alpha" "beta" "gamma" )
>
> It's as if it does not recognize the difinition of the macro that it parsed. Has somebody ran into this problem?
>
>
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: How can I define a macro in different file and use it?
Posted by Markus Reinhardt <mr...@hygiene.uni-wuerzburg.de>.
...I hit the wrong button :(
Velocity Manual:
*Velocimacro Properties*
Several lines in the |velocity.properties| file allow for flexible
implementation of Velocimacros. Note that these are also documented in
the Developer Guide
<http://jakarta.apache.org/velocity/docs/developer-guide.html>.
|velocimacro.library| - A comma-separated list of all Velocimacro
template libraries. By default, Velocity looks for a single library:
/VM_global_library.vm/. The configured template path is used to find the
Velocimacro libraries.
...
*Can I register Velocimacros via #parse() ? *
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.
...
Hope this helps,
Markus
Colbert Philippe schrieb:
> I tried to define a simple macro in one file and using it in another macro file. I attempted to do this using #parse. This is an important functionality for programmers.
>
> Defining a simpel macro in macrolibrary.vm
> ## This macro simply prints its 3 parameters separated by single space
> #macro( myMacro $p1 $p2 $p3 )
> $p1 $p2 $p3
> #end
>
> Using it in separate file usingmymacro.vm
>
> #parse( "macrolibrary.vm" )
>
> #myMacro( "alpha" "beta" "gamma" )
>
> Output of running Velocity with my file usingmymacro.vm
>
> #myMacro( "alpha" "beta" "gamma" )
>
> It's as if it does not recognize the difinition of the macro that it parsed. Has somebody ran into this problem?
>
>
>
>
>
>
>
>