[Templates] trying to leave HTML::Mason for TT2
Craig McLane
mclanec@oxy.edu
Fri, 4 Aug 2000 18:20:31 -0700 (PDT)
On 4 Aug 2000, Randal L. Schwartz wrote:
> How do I do the equivalent of the "autohandler" and "defaulthandler"
> under mod_perl? I think I can write a mod_perl handler that looks for
> a PerlSetVar TTAutoHandler and if present, invokes that template
> instead of the file directly. However, is there a consistent way to
> tell that template what the original file was? I suppose I could just
> pass "$r" as one of the vars, and pull them out?
At citysearch we are using a Model/View/Controller like paradigm where
specific handlers act as the Controller, TT2 is the View and other libs
are the Model (Perrin is my hero). We also have a set of error handlers
(eg 403, 404, 500) which hand off a variety of parameters to the template
including the uri, cookie info, etc. The templates on the whole use the
basic concept of includes to make decisions within an INCLUDE_PATH that
changes on each request. This allows us to make top level templates act
as shells that include content, other template MACRO definitions, etc
based on the parameters passed to them.
Essentially our shell templates will be very minimal and have includes
like:
[% INCLUDE ${foo.header} %]
[% INCLUDE ${bar.context}/${baz.quix}_${foo.baz}_leftnav.html %]
[% INCLUDE ${bar.context}/${baz.flavor_of_the_month}.html %]
[% INCLUDE ${bar.context}/${baz.quix}_${foo.baz}_rightnav.html %]
[% INCLUDE ${foo.footer} %]
which take care of figuring out what the page ends up containing. We use
the INCLUDE_PATH like a giant if/else tree. Wherever the file we want to
include resides, it will be pulled in. Our INCLUDE_PATH looks like:
/foo/losangeles/section/music
/foo/losangeles/section
....
/foo/default
This way we are able to try to pull in includes in order of specificity to
the parameters of the request for a given page.
I'm sure I'm rambling now, so I don't know if any of this makes sense.
Craig