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/11 06:02:47 UTC

What is the difference between a macro and a template

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