You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Peter Sojan <il...@gmx.net> on 2002/01/22 04:46:01 UTC

library questions ...

Hi all!

I don´t know if anyone knows/uses Engelschalls "Website Meta Language"
(http://www.engelschall.com/sw/wml/). Albeit this template/macro language 
is for static page generation and is geared towards slightly other 
goals as velocity I try to mimic some habits i adopted with WML.  

Actually I have 2 questions:

As I understand the only way to include libraries is via properties
in the velocity configuration on startup. Is it possible to reference
from macros in one library to macros in other libraries !? Will Velocity
resolve such nesting correctly!?

What is the best way to define global variables (e.g. for color 
definitions)!? I would like to see them within my libraries along
with my custom macros. However I noticed that variables defined 
in libraries are not visible from normal templates. Should I 
#parse my libraries to get my globals in addition to my macros!?


another question besides: are there any plans for "real" <includes>
in Velocity so that I don´t habe to define libraries via 
properties beforehand? What are the reasons behind that?

Thx,
Peter
 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: library questions ...

Posted by Peter Sojan <il...@gmx.net>.
On Tue, Jan 22, 2002 at 04:12:43AM -0500, Geir Magnusson Jr wrote:
> 
> One solution is to define a VM
> 
> #macro( loadglobals )
>   #set( $foo = "hello")
>   #set( $name = "Peter")
> #end

Ok, I think I´ll stick with that ..

> > 
> > another question besides: are there any plans for "real" <includes>
> > in Velocity so that I don´t habe to define libraries via
> > properties beforehand? What are the reasons behind that?
> > 
> 
> You can #macro() anywhere, but I assume you want to #include() a macro
> library in a template?  (it really would be #parse() )
> 
Yes, when first reading the docs, one thinks that #parse is really 
meant for including libraries. I guess there are internal issues which
prevent such a solution ...

Thx Geir!

Peter


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: library questions ...

Posted by Geir Magnusson Jr <ge...@optonline.net>.
On 1/21/02 10:46 PM, "Peter Sojan" <il...@gmx.net> wrote:

> 
> Hi all!
> 
> I don´t know if anyone knows/uses Engelschalls "Website Meta Language"
> (http://www.engelschall.com/sw/wml/). Albeit this template/macro language
> is for static page generation and is geared towards slightly other
> goals as velocity I try to mimic some habits i adopted with WML.
> 
> Actually I have 2 questions:
> 
> As I understand the only way to include libraries is via properties
> in the velocity configuration on startup. Is it possible to reference
> from macros in one library to macros in other libraries !? Will Velocity
> resolve such nesting correctly!?

I assume you mean macro libraries?

Yes - you can call across macro libraries if you wish, and Vel will handle
it.

> 
> What is the best way to define global variables (e.g. for color
> definitions)!? I would like to see them within my libraries along
> with my custom macros. However I noticed that variables defined
> in libraries are not visible from normal templates. Should I
> #parse my libraries to get my globals in addition to my macros!?

You could do that. 

The reason you can't do that in libraries is that there is no context for
them to 'stick' to, as the libraries are loaded before any application
processing happens.

One solution is to define a VM

#macro( loadglobals )

  #set( $foo = "hello")
  #set( $name = "Peter")

#end

And then invoke this at the top of each template.

Another solution is to build something in your servlet/application to
preload the context automatically.
 
> 
> another question besides: are there any plans for "real" <includes>
> in Velocity so that I don´t habe to define libraries via
> properties beforehand? What are the reasons behind that?
> 

You can #macro() anywhere, but I assume you want to #include() a macro
library in a template?  (it really would be #parse() )



-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>