You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Robert Edgar <ro...@eeplace.com> on 2001/11/10 19:31:17 UTC

Dynamic Nested Templates

I am trying to convert existing pages that use xsl into Velocity.

What I want to know is how to implment the following style in Velocity...

<xsl:template match="/page">
	<xsl:call-template name="stdPage">
		<xsl:with-param name="SideBar">
			<xsl:call-template name="SideBar"/>
		</xsl:with-param>
		<xsl:with-param name="panelC">
			<xsl:call-template name="FeatureBoxes" />
		</xsl:with-param>
		<xsl:with-param name="panelR">
			<xsl:call-template name="banner125">
				<xsl:with-param name="index" select="2"/>
			</xsl:call-template>
			<xsl:call-template name="banner125">
				<xsl:with-param name="index" select="3"/>
			</xsl:call-template>
			<xsl:call-template name="banner125">
				<xsl:with-param name="index" select="4"/>
			</xsl:call-template>
		</xsl:with-param>
	</xsl:call-template>
</xsl:template>

If it isn't obvious what I have is a global template which is a standard
page with a left,center and right columns which I will fill with the
contents of parsing other templates. ie I want to call a template and pass
it a parameter which is the result of parsing another template.

I cant see how this is done in Velocity.


Rob


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


Re: What is the difference between a macro and a template

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/11/01 12:02 AM, "Robert Edgar" <ro...@eeplace.com> wrote:

> Excuse me if these are dumb questions.
> 
> I understand that a macro can be defined inline, and I also understand how
> it can be used to save typing for small code snippets OK but taking a step
> back and looking at a larger use of macro's I understand that a macro can
> contain anything a template can.
> 
> So what difference is there between #parse'ing a template and calling a
> macro?
> 
> I know macro can be loaded into a global library, is their some inherent or
> performance advantage to take a large template and turn it into a global
> macro if it is used frequently by many other templates?  or are macro's just
> a convenience method but aren't really any different from a template?

There actually are a few differences.

The biggest is that the #macro() takes parameters.  This is important
because I think it makes your templates more readable, and 'causal'.
Instead of hoping that the array in the template bar.vm is called
'$fooarray', as in

#set($fooarray = $myarray)
#parse( "bar.vm" )

By using a VM

#barmacro( $myarray )

It's definite what is going on.

There are also some other properties of VMs, such as private namespaces and
'local context', which you can't get with templates...

geir


-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



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


What is the difference between a macro and a template

Posted by Robert Edgar <ro...@eeplace.com>.
Excuse me if these are dumb questions.

I understand that a macro can be defined inline, and I also understand how
it can be used to save typing for small code snippets OK but taking a step
back and looking at a larger use of macro's I understand that a macro can
contain anything a template can.

So what difference is there between #parse'ing a template and calling a
macro?

I know macro can be loaded into a global library, is their some inherent or
performance advantage to take a large template and turn it into a global
macro if it is used frequently by many other templates?  or are macro's just
a convenience method but aren't really any different from a template?

Rob


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


RE: Dynamic Nested Templates -Don't Agree that this is not what Velo is for

Posted by Robert Edgar <ro...@eeplace.com>.
Thanks Geir,
By fixed I think what I meant was, refering to your example below, that the
BODY template was a static reference.

I hadnt thought of using variables for templates names.

Also fixed in that the body template is one template whereas we might have 4
template that together constitute the body for pageX, I know you could just
use another template to aggregate those template but it just looked like
more and more files whereas the beauty of the XSLT approach is one single
file can aggregate templates for the body and also aggregate templates for
the leftnav, rightnav etc.

Also taking your example the frame page for us would just be another generic
template rather than specific to a page, with XSLT essentialy I can say "use
template1 and within template1 replace the leftnav with the content of tpl2,
tpl3 and tpl4"
and on the next call say  "use template1 and within template1 replace the
leftnav with the content of tpl5, tpl6". Template assembly or aggregation
becomes very dynamic.

Velocity can do this AFAIK ... just wasnt obvious at first glance.... XSLT
is beautiful and easy to use, and the only reason we are now looking at
Velocity is that we are moving to using a caching technology and each page
will use Edge Side Includes(ESI) to generate the trully dynamic content and
the rest of the page is now static html templates so we want to use a system
to pregenerate these static html templates from a collection of
sub-templates retaining XSLT to be accessed by the ESI for generating
dynamic content on the fly.

Rob

-----Original Message-----
From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
Sent: Sunday, November 11, 2001 10:59 AM
To: velocity-user@jakarta.apache.org
Subject: Re: Dynamic Nested Templates -Don't Agree that this is not what
Velo is for


On 11/10/01 9:05 PM, "Robert Edgar" <ro...@eeplace.com> 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
example.

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


<table>
 <tr>
   <td colspan=2>
       #parse( $header )
   </td>
 </tr>
 <tr>
    <td>
       #parse( $leftnav )
    </td>
    <td>
       #parse( $body )
    </td>
 </tr>
 <tr>
    <td colspan=2>
     #parse($footer)
    </td>
 </tr>
</table>

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
> AND
>
> 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.

Hm

> 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

--
Geir Magnusson Jr.     geirm@optonline.net
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:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>




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


Re: Dynamic Nested Templates -Don't Agree that this is not what Velo is for

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/10/01 9:05 PM, "Robert Edgar" <ro...@eeplace.com> 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
example.

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


<table>
 <tr>
   <td colspan=2>
       #parse( $header )
   </td>
 </tr>
 <tr>
    <td>
       #parse( $leftnav )
    </td>
    <td>
       #parse( $body )
    </td>
 </tr>
 <tr>
    <td colspan=2>
     #parse($footer)
    </td>
 </tr>
</table>

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
> AND
> 
> 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.

Hm

> 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

-- 
Geir Magnusson Jr.     geirm@optonline.net
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Dynamic Nested Templates -Don't Agree that this is not what Velo is for

Posted by Robert Edgar <ro...@eeplace.com>.
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 .

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

AND

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.

So ....  correct me if I am wrong .... but to me this is exactly what Velo
is about and it can do what I want...

Rob


-----Original Message-----
From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
Sent: Sunday, November 11, 2001 4:36 AM
To: velocity-user@jakarta.apache.org
Subject: Re: Dynamic Nested Templates


On 11/10/01 2:46 PM, "LS" <al...@yahoo.com> wrote:

> Robert, I think what you are looking for is a web development framework.
> Velocity,
> on the other hand, is a templating engine that happens to work very well
with
> web
> frameworks. Several web frameworks exist, and I can recommend Maverick as
a
> very
> small, simple, free, and usable way to wrap a framework around Velocity
pages.
> Turbine, also from the Jakarta project, performs this role, along with
doing a
> lot
> of other things.
>
> Geir et al, I wonder if it makes sense to write up a quick blurb on this
topic
> and
> put it somewhere visible, like Velocity FAQ?

That's a good idea.  Will do.

>
> --- Robert Edgar <ro...@eeplace.com> wrote:
>> I am trying to convert existing pages that use xsl into Velocity.
>>
>> What I want to know is how to implment the following style in Velocity...
>>
>> <xsl:template match="/page">
>> <xsl:call-template name="stdPage">
>> <xsl:with-param name="SideBar">
>> <xsl:call-template name="SideBar"/>
>> </xsl:with-param>
>> <xsl:with-param name="panelC">
>> <xsl:call-template name="FeatureBoxes" />
>> </xsl:with-param>
>> <xsl:with-param name="panelR">
>> <xsl:call-template name="banner125">
>> <xsl:with-param name="index" select="2"/>
>> </xsl:call-template>
>> <xsl:call-template name="banner125">
>> <xsl:with-param name="index" select="3"/>
>> </xsl:call-template>
>> <xsl:call-template name="banner125">
>> <xsl:with-param name="index" select="4"/>
>> </xsl:call-template>
>> </xsl:with-param>
>> </xsl:call-template>
>> </xsl:template>
>>
>> If it isn't obvious what I have is a global template which is a standard
>> page with a left,center and right columns which I will fill with the
>> contents of parsing other templates. ie I want to call a template and
pass
>> it a parameter which is the result of parsing another template.
>>
>> I cant see how this is done in Velocity.
>>
>>
>> Rob
>>
>>
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Find a job, post your resume.
> http://careers.yahoo.com
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>

--
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



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




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


Re: Dynamic Nested Templates

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/10/01 2:46 PM, "LS" <al...@yahoo.com> wrote:

> Robert, I think what you are looking for is a web development framework.
> Velocity,
> on the other hand, is a templating engine that happens to work very well with
> web
> frameworks. Several web frameworks exist, and I can recommend Maverick as a
> very
> small, simple, free, and usable way to wrap a framework around Velocity pages.
> Turbine, also from the Jakarta project, performs this role, along with doing a
> lot
> of other things.
> 
> Geir et al, I wonder if it makes sense to write up a quick blurb on this topic
> and
> put it somewhere visible, like Velocity FAQ?

That's a good idea.  Will do.

> 
> --- Robert Edgar <ro...@eeplace.com> wrote:
>> I am trying to convert existing pages that use xsl into Velocity.
>> 
>> What I want to know is how to implment the following style in Velocity...
>> 
>> <xsl:template match="/page">
>> <xsl:call-template name="stdPage">
>> <xsl:with-param name="SideBar">
>> <xsl:call-template name="SideBar"/>
>> </xsl:with-param>
>> <xsl:with-param name="panelC">
>> <xsl:call-template name="FeatureBoxes" />
>> </xsl:with-param>
>> <xsl:with-param name="panelR">
>> <xsl:call-template name="banner125">
>> <xsl:with-param name="index" select="2"/>
>> </xsl:call-template>
>> <xsl:call-template name="banner125">
>> <xsl:with-param name="index" select="3"/>
>> </xsl:call-template>
>> <xsl:call-template name="banner125">
>> <xsl:with-param name="index" select="4"/>
>> </xsl:call-template>
>> </xsl:with-param>
>> </xsl:call-template>
>> </xsl:template>
>> 
>> If it isn't obvious what I have is a global template which is a standard
>> page with a left,center and right columns which I will fill with the
>> contents of parsing other templates. ie I want to call a template and pass
>> it a parameter which is the result of parsing another template.
>> 
>> I cant see how this is done in Velocity.
>> 
>> 
>> Rob
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Find a job, post your resume.
> http://careers.yahoo.com
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



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


Re: Dynamic Nested Templates

Posted by LS <al...@yahoo.com>.
Robert, I think what you are looking for is a web development framework. Velocity,
on the other hand, is a templating engine that happens to work very well with web
frameworks. Several web frameworks exist, and I can recommend Maverick as a very
small, simple, free, and usable way to wrap a framework around Velocity pages.
Turbine, also from the Jakarta project, performs this role, along with doing a lot
of other things.

Geir et al, I wonder if it makes sense to write up a quick blurb on this topic and
put it somewhere visible, like Velocity FAQ?

--- Robert Edgar <ro...@eeplace.com> wrote:
> I am trying to convert existing pages that use xsl into Velocity.
> 
> What I want to know is how to implment the following style in Velocity...
> 
> <xsl:template match="/page">
> 	<xsl:call-template name="stdPage">
> 		<xsl:with-param name="SideBar">
> 			<xsl:call-template name="SideBar"/>
> 		</xsl:with-param>
> 		<xsl:with-param name="panelC">
> 			<xsl:call-template name="FeatureBoxes" />
> 		</xsl:with-param>
> 		<xsl:with-param name="panelR">
> 			<xsl:call-template name="banner125">
> 				<xsl:with-param name="index" select="2"/>
> 			</xsl:call-template>
> 			<xsl:call-template name="banner125">
> 				<xsl:with-param name="index" select="3"/>
> 			</xsl:call-template>
> 			<xsl:call-template name="banner125">
> 				<xsl:with-param name="index" select="4"/>
> 			</xsl:call-template>
> 		</xsl:with-param>
> 	</xsl:call-template>
> </xsl:template>
> 
> If it isn't obvious what I have is a global template which is a standard
> page with a left,center and right columns which I will fill with the
> contents of parsing other templates. ie I want to call a template and pass
> it a parameter which is the result of parsing another template.
> 
> I cant see how this is done in Velocity.
> 
> 
> Rob
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

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