On Mon, Sep 30, 2002 at 10:40:57AM -0400, Perrin Harkins wrote:
> Are you just trying to figure out how to bundle up a chunk of template 
> and call it multiple times?  In that case, PROCESS is most commonly the 
> option you want.  Use INCLUDE only if you need to isolate the current 
> state of the template variables so they can't be changed inside the 
> included template.  Use MACRO if you have a really tiny thing that 
> doesn't merit a separate file.

I'd say, rather, use MACRO when you want to use named arguments to keep
your templates cleaner, or want to be able to nest things. Or even when
you want to hide the implementation details from the template.

So, for example, on most web sites I do, I have a 

  MACRO title(page_title)   INCLUDE comp/page_title;

This means that I don't need to remember where the page_title template
lives all the time, and also makes it much easier to change how where
it's stored, or even how it's implemented, later, without changing lots
of templates.

Similarly I use things like:

  MACRO html_enc(text) BLOCK; text | html; END;

and

  MACRO h2(style, text) BLOCK; CGI.h2({ class=style }, text); END;   [1]

So I can do things like:

  [% h2("subTitle", html_enc(foo.name)) %]

I find it makes my templates much cleaner...

Maybe the explicit PROCESS and INCLUDE directives just remind me too
much of bad imperative programs I've had to work with ...


Tony

[1] Note the crafty trick: by making the text the 2nd argument I'm never
tempted to leave the CSS class out ...)

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates

Reply via email to