velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: macros in other templates
Date Sat, 09 Mar 2002 15:05:37 GMT
On 3/9/02 9:56 AM, "Sebastien Chassande-Barrioz"
<sebastien.chassande@inrialpes.fr> wrote:

>> I assume you meant #parse("file1.vm"), and yes, that doesn't work.
> 
> yes, sorry for my mistake
> 
>> The reason is that #parse() is a 'run-time' thing, and the decision of
>> resolving #writeImports() to be VM is a 'parse-time' thing.
> 
> ok, I understand.
> 
>> Yes - there is a feature called Velocimacro libraries, in which you
>> can define lots of VMs, and they are accessible to all other
>> templates.
>> See the docs on how to configure Velocity to load the libraries on
>> startup.
> 
> What does contain the velocimacro.library properties ?
> A comma list of directories where to find .vm files or a comma list of
> .vm files ?

The files.

It uses the configured loaders to find the files, to the library files must
be findable via the configured loaders - just like any other template.

So put the library with your other templates, and all will be well.

> 
> Is this (my) initialization is compatible with the velocimacro feature:
> 
> VelocityEngine ve = new VelocityEngine();
> ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this);
> ve.setProperty( "velocimacro.library", "/src/templates/file2.vm");
> ve.init();
> 
> Is it possible to specify the velocimacro property by this way ?

Yes in concept, but unless you are sitting in the root directory "/", the
above won't work.

Here's why : the libraries are loaded via the normal template loaders.  The
default configuration is to use the file loader and make the 'current
directory' the default path to look for templates.

The file loader ignores  'absolute' template specifications, and just
searches for the specified template relative to the one or more directories
it was configured with.

So I would redo the above as

VelocityEngine ve = new VelocityEngine();
ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this);
ve.setProperty( VelocityEngine. FILE_RESOURCE_LOADER_PATH,
           "/src/templates");
ve.setProperty( "velocimacro.library", "file2.vm");
ve.init();

And that should work.

Geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
My inner cowboy needs to yodel.


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


Mime
View raw message