On Tue, 04 Jan 2005 14:55:59 -0500, Perrin Harkins <[EMAIL PROTECTED]> wrote:
> On Mon, 2005-01-03 at 21:38 -0500, Cees Hek wrote:
> > I don't know exactly how Perrin does this, but I thought it might be a
> > good time for me to mention CGI::Application::Plugin::TT which is a
> > Template Toolkit plugin for CGI::Application.  It does pretty much
> > what Perrin is describing above (in the context of CGI::Application).
> > Probably not very useful if you don't use CGI::Application, but you
> > may get some useful ideas from it.
> >
> > http://search.cpan.org/~ceeshek/CGI-Application-Plugin-TT-0.04/lib/CGI/Application/Plugin/TT.pm
> 
> Looks nice, Cees.  Any chance you could add an easy way to modify the
> INCLUDE_PATH?  It could be done with the accessors you provided, but it
> would require direct manipulation of the TT object.

I usually set the INCLUDE_PATH on a per class basis, so I haven't
found a need for it.  Do you have any ideas on how to cleanly
implement that?  I didn't even know it was possible until I saw your
message on it yesterday.

Here is how I usually handle setting the INCLUDE_PATH dynamically
(this is of course using CGI::Application::Plugin::TT under
CGI::Application):

sub cgiapp_init {
  my $self = shift;
  $self->tt_config(
            TEMPLATE_OPTIONS => {
                      INCLUDE_PATH => $self->site->config('TEMPLATE_PATH'),
                      DELIMITER    => ':',
                      COMPILE_DIR  => '/tmp/tt_cache',
            },
  );
}

Where $self->site returns a Class::DBI table object that selects the
correct 'site' record based on $ENV{SERVER_NAME}.  And
$self->site->config looks up a config option in the database for that
site.  This allows me to run multiple websites on the same codebase,
all sharing the same database.  And in this case, it is setting a
custom INCLUDE_PATH for each website, allowing for custom skinning
(you could easily base this on username to do per user skinning as
well).

This works well for me.  But then again, I am not caching these
objects across requests, which it sounds like you may be doing.  I
mostly use PersistentPerl instead of mod_perl, and I try to let
everything go out of scope after every request (nice and easy to do
with CGI::Application).

I'll have to look back at your example from the other day, but from
what I remember, it looks like changing the INCLUDE_PATH would change
it for all subsequent calls to 'process'.  Is that correct?  Would
that be an acceptable behaviour?  If so, then it would be pretty easy
to add.  If not, then would it maybe be possible to use some 'local'
magic to localize a change to the INCLUDE_PATH?

Cheers,

-- 
Cees Hek

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

Reply via email to