Mihai Bazon wrote:
> <html>
> ... header content
> % $m->next_comp
> ... footer content
> </html>

The closest thing to a TT equivalent is to use a PROCESS template.  This is
called instead of your main template (but which is still accessible via the
template var)

<html>
   ...header content...
   [% PROCESS $template %]
   ...footer content...
</html>

> Now, in /admin/autohandler you can have the following:
> 
> % if ($has_admin_privileges) {
> % $m->next_comp;  # display admin page
> % } else {
> ... display login form ...
> % }

This is the bit that TT doesn't support.  You have to define a single PROCESS
template up front.  You can't just drop a new one in a directory like you can
with Mason.

If there's not much in the way of access/layout logic in the site then you
could cram it all into one master PROCESS template.  Something like this:

   [% IF template.name.match('admin') %]
       ...
   [% ELSE %]
       ...
   [% END %]

However, that doesn't scale so well when you've got lots of different
sections.  My usual approach is to define a sitemap that contains metadata
for each page and/or section of the site. I typically use a YAML file, e.g.

    /index.html:
      name: Home
      title: My Funky Home Page
    /admin/index.html:
      name: Admin
      title: Administration
      layout: admin

Then in a PRE_PROCESS template, I'll load up the page metadata like so:

    USE sitemap("/path/to/my/sitemap.yaml");   # simple YAML loader
    uri  = "/$template.name"
    page = sitemap.$uri

Then I use my master PROCESS template to load up the right layout/access
template based on what the current page metadata says.

   layout = page.layout or 'default'
   PROCESS "layout/$layout";

So my /index.html page will use layout/default and /admin/index.html
will use "layout/admin".

To avoid having to define a layout option for every single page, I'll
typically add one to the metadata for the parent section like so:

   /admin/:
     layout: admin
   /admin/index.html
     name: Admin
     title: Administration

Then I twiddle my sitemap loader to "inherit" layout values from section
to page.  Sorry, I don't have any generic plugin code to handle this, but
I can paste some examples if anyone's interested.

Anyway, the basic principle/recipe is to define a sitemap containing all the
metadata for the site and use values defined therein to declare what layout,
handler or other juju you want applied to each template.  It's more
roll-your-own than Mason's autohandlers, but I think it gives you more
(or at least as much) flexibility in the long run.

If you don't want the overhead of a separate metadata file (but trust me,
it's probably worth it for all but the simplest sites), then you can use
META items in the page templates instead:

   [% META layout = 'admin' %]
   Blah blah admin page

Then in the main PROCESS layout template you look for template.layout instead
of page.layout:

   layout = template.layout or 'default'
   PROCESS "layout/$layout";

HTH
A

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to