Re: [Templates] setting META data in process()

[prev] [thread] [next] [Date index for 2005/01/09]

From: Andy Wardley
Subject: Re: [Templates] setting META data in process()
Date: 09:40 on 09 Jan 2005
Bill Moseley wrote:
> Or do I need to pass in a separate "mytemplate" hash?
[...]
> and then in my templates do:
> 
>    [% foo = mytemplate.foo || template.foo %]

My usual approach is to have a pre-process template construct a 'page'
data structure, using the template metadata or any other data you have.

config/page:

    [% page = {
         title  = template.title  or some_other_data.title
         author = template.author or 'Andy Wardley'
         ...etc...
       }
    %]

And then in my templates, I access page.whatever rather than 
template.whatever.  This keeps all your page setup logic in one 
place.  If you later decide to store page metadata in a database,
XML file, or something else, then you only need to hack on the 
config/page file to make things work anew.

You can even overwrite the 'template' item if you don't mind burning
your bridges:

    [% template = {
           ...as above...
       }
    %]

The Badger Book has some more detailed examples in ch11, in the "Library
Templates" section, starting on page 406.

Cheers
A


_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] setting META data in process()
Bill Moseley 20:41 on 08 Jan 2005

Re: [Templates] setting META data in process()
Andy Wardley 09:40 on 09 Jan 2005

[Templates] Slashdot Templating article
Leo Lapworth 10:33 on 09 Jan 2005

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52