Hi Perrin,

Perrin Harkins wrote:
 > You sort of can.  If you set the INCLUDE_PATH based on the request
 > (e.g. [ '/foo/bar', '/foo', '/' ] ), you get inheritance like Mason's
 > and can use WRAPPER or PROCESS with overring.

Ah yes, good point.

The walkup paths that TT3 will support should make this kind of thing
much easier. e.g

    Template->new(
        PROCESS => '.../layout',
    );

Relative paths are resolved against the current template path, and the '...'
means "walk up from here until you find it".  So if you process
/foo/bar/index.html then it will use the first layout it finds from
/foo/bar/layout, /foo/layout or /layout.

The nice thing is that this will work across different template providers.
So you don't have to put your layout template in the same directory as your
page template.  Instead you can put it in a directory of the same name under
a separate location, along with your other library components.

    INCLUDE_PATH => [ '/my/templates/pages', '/my/templates/layouts' ],

    /my/templates/pages/foo/bar/index.html   # page template
    /my/templates/layouts/foo/bar/layout     # layout template

 > What you don't get is an
 > equivalent to $m->call_next, so layering them would be tricky.
 > Overriding works very well though.

This is something that I'm keen to add to TT3, but I can't quite figure out
the best way to do it.

The simple and easy way is to fetch all possible matching templates, pop the
first one off the list and call it, passing the list of the remaining
candidate templates. The downside is that it makes the general case slower
because you're finding all templates every time, not just the first.

The other approach would be to return just the nth template, where n defaults
to 0.  If a template somehow "knows" that it's the nth template then it's
relatively easy for it to delegate to the (n+1)th.   But that smells a bit
messy to me and would be fragile in the face of a dynamic include path.

But one way or another, I'm planning to make more of inheritance-like
behaviours in TT3.

Cheers
A



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

Reply via email to