velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: Dynamic Nested Templates -Don't Agree that this is not what Velo is for
Date Sun, 11 Nov 2001 02:58:57 GMT
On 11/10/01 9:05 PM, "Robert Edgar" <> wrote:

> Guys,
> Maybe I didn't explain myself clearly, my fault!
> No problem, anyway here is my "take" on things.
> I understand that Velocity is a templating engine, we are currently using
> XSL as our templating engine, I have a standard "template" which is a large
> XSL stylesheet, actually I have several "standard" templates covering
> different sorts of pages that I have on my web site. Within a standard
> template I then load sub-templates to format different sections, so on my
> site home page I have the main page template and sub templates for a section
> on latest news .

So far so good.  This is the kind of thing you can do with #parse(), for

> Now to me this is EXACTLY what velocity is about.
> The only issue I had here was that Velocity "seemed" to require a template
> to be fixed rather than dynamic in that although it can have nested
> templates,

What do you mean 'fixed'?

A common technique is to setup a 'frame' or 'layout' that positions the
parts of the page, such as the top, nav section, footer, and body, and then
you use references to setup all the parts.... Something like

   <td colspan=2>
       #parse( $header )
       #parse( $leftnav )
       #parse( $body )
    <td colspan=2>

And then the servlet choose the $header, $leftnav, $body and $footer based
on user and current context of the app.
Just one approach among many...

> using the #parse directive, these are preset in the template
> whereas I wanted something dynamic in that a template will display a VAR at
> a point in the template but I want the VAR to be the output of #parse some
> previous template.

#parse() can take references, so the actual thing can be chose independently
of the framing/layout tempalte
> After looking a bit father myself it "seems" to me my "standard" templates
> can be loaded as Velocity Macro's in the form of the global library.


> My
> understanding is that a Macro is called and is passed parameters which can
> be anything including the rendered output of another template. If that is
> the case that almost exactly matches an XSL call-template directive.

Sure.  You can do something like

#set($templateoutput = "#parse($foo)")

#myvelocimacro( $templateoutput )

(note the " in the #set() )
> So ....  correct me if I am wrong .... but to me this is exactly what Velo
> is about and it can do what I want...

Then switch as fast as you can :)

I like XSL but I think it's really challenging for the view layer :)


Geir Magnusson Jr.
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin

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

View raw message