[Templates] Process vs Macro ?

Josh Rosenbaum josh@infogears.com
Fri, 22 Sep 2006 10:05:51 -0600


Perrin Harkins wrote:
> Evan Carroll wrote:
>> Could someone please juxtapose PROCESS w/ ARGS, vs, MACRO? I'm confused
>> as to which one to use.
> 
> It's a matter of scope.  If want to split out some repeated code that no 
> other template will use, make it a MACRO in the current template.  If 
> you have something that other templates might conceivably use too, make 
> it a separate template and call it with PROCESS.
> 
> In practice, I have almost no use for MACRO.
> 
> - Perrin

I agree with this. I don't use MACRO very much. For functions I find useful, I usually pass them into TT via the vars parameter. There may be the occasional Template that needs special code, though.

PROCESS/INCLUDE gives you more control over the scoping of variables than if you are using a MACRO with a BLOCK. I think for MACROs (at least with BLOCKs), all of the data is cloned before the BLOCK is processed. That means it is doing an INCLUDE rather than a PROCESS. (So changes to scalars will not show up.)

-- Josh