velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: What is the difference between a macro and a template
Date Sun, 11 Nov 2001 09:02:15 GMT
On 11/11/01 12:02 AM, "Robert Edgar" <> 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 Magnusson Jr.             
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:   <>
For additional commands, e-mail: <>

View raw message