velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: macros in other templates
Date Sat, 09 Mar 2002 14:02:10 GMT
On 3/9/02 8:59 AM, "Sebastien Chassande-Barrioz"
<> wrote:

> hi,
> The call to a macro localized in an other template file, does not work.
> View of both files:
> File1.vm:
> #macro ( writeImports )
> toto
> #end
> File2.vm:
> #parse ("File2.vm")
> #writeImports()

I assume you meant #parse("file1.vm"), and yes, that doesn't work.

> The "#writeImports()" string is written in the result intead of the
> "toto" string. I tried to use the #include command instead of #parse but
> in this case the text of macro is written and not the result.

The reason is that #parse() is a 'run-time' thing, and the decision of
resolving #writeImports() to be VM is a 'parse-time' thing.

> Do you have some suggestions to resolve my problem ?

Yes - there is a feature called Velocimacro libraries, in which you can
define lots of VMs, and they are accessible to all other templates.

The library format is very simple - just define the VMs

Hello from foo

#macro(bar $a
 $a => bar


See the docs on how to configure Velocity to load the libraries on startup.

Geir Magnusson Jr.                           
System and Software Consulting
The question is : What is a Mahnamahna?

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message