velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Reinhardt <>
Subject Re: How can I define a macro in different file and use it?
Date Sun, 02 Jul 2006 10:50:54 GMT
...I hit the wrong button :(

Velocity Manual:

*Velocimacro Properties*

Several lines in the || file allow for flexible
implementation of Velocimacros. Note that these are also documented in
the Developer Guide

|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,


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?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message