[Templates] trying to leave HTML::Mason for TT2
Perrin Harkins
pharkins@etoys.com
Fri, 4 Aug 2000 18:10:09 -0700 (PDT)
On 4 Aug 2000, Randal L. Schwartz wrote:
> Pardon me if these things would have been discovered in hour 4 of
> reading through the docs and looking at the test code, but I'm just
> trying to see if I'm investing my time wisely, and have so far only
> spent a few hours with the TT2 beta dist.
If you haven't already, read the paper at
http://www.template-toolkit.org/tpc4/paper.html. It gives examples for
use with mod_perl.
> 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?
That's what the example handler does.
> And what about caching the results of calculations? Has anyone done a
> cache plugin, or had experience using any of the dozen caching
> solutions in a multiuser environment to share the results?
There's no caching built into TT and no plugin for it yet. I do data
caching in my handler before running TT (with BerkeleyDB), and page
caching in mod_proxy in front of the mod_perl server.
> And can we get the equivalent of inheritance?
I do this by varying the template include path on different requests.
That way I can always call "topbar.html" but I can override which file
that is in certain areas of the site.
/topbar.html
/co-brand_1/topbar.html
/co-brand_2/topbar.html
> Can I open a file and include it arbitrarily, rather than have it
> examined via INCLUDE for template codes? I suppose I could set the
> template triggers to be something very unlikely, but is there a way of
> just saying "put this file here"?
Not built in. It might be nice to steal a feature from Mason and handle
purely static templates as a special case. When you INCLUDE (actually I
always use PROCESS, since it's faster and I don't need to preserve
variables) a template that has no special codes in it, that file could be
left on disk and sucked in dynamically each time.
- Perrin