[Templates] Re: Template::Toolkit questions

Andy Wardley abw@cre.canon.co.uk
Tue, 1 Aug 2000 15:12:33 +0100


On Jul 28,  8:22pm, Paul Makepeace wrote:
> On Jul 28, 12:50am, Paul Makepeace wrote:
> Is there a way to automatically, if the file can't be found in the
> INCLUDE_PATH to use a default file?
[...]
> Thanks! Right now I'm initiating the processing from the mod_perl handler
> so I'm not entirely sure how I'd use these commands.

OK, in that case you can use the ERROR hash to do an automatic redirect.

> I guess a 2.0 thing? CPAN didn't think T::P was around yet.
> <faq>Shall I just go ahead and use 2.0 as it stands?</faq>

Yep, dive straight into version 2.

> The problem (or really disadvantage) is that before I could simply say
> 'images/boss.gif' and exploit TT's neat INCLUDE_PATH idea to 'overload'
> the templates version simply by uploading a different image into the
> client-specific area, if they wanted their own version instead. Or
> replacement text for some part of the site or whatever. Now I've
> effectively hardcoded the data path.
>
> I don't really see a way around this though.

Perhaps there's a need for a simple Apache handler which delivers files
from an INCLUDE_PATH?  Actually, I'd be surprised if this doesn't already
exist, but I don't know of one off the top of my head.

> Additional question! I might be misunderstanding something but
> the general paradigm here seems to encourage absolute paths
> so in a random directory [% INCLUDE header.txt %] searches the
> INCLUDE_PATH rather than (for me anyway!) the more intuitive the
> current directory.

Yep, that's right.

Version 2 allows you to modify the INCLUDE_PATH at any time and have
the Right Thing happen.  One solution might be to modify the INCLUDE_PATH
for each request, effectively shifting the client_src/$client_name onto
the front for each specific request.  I haven't tried this myself, so I
can't show you any code, but there might be an elegant solution in there
somewhere.


A



-- 
Andy Wardley <abw@kfs.org>   Signature regenerating.  Please remain seated.
     <abw@cre.canon.co.uk>   For a good time: http://www.kfs.org/~abw/