* Ryan Thompson <[EMAIL PROTECTED]> [2002-08-21 15:40]:
> I would like to specify a number of "allowed" directories for a single
> template object (as in the INCLUDE_PATHs), but at runtime, be able to
> specify from which directory to get the files.

You need to use multiple template objects, or modify INCLUDE_PATH at
runtime.  INCLUDE_PATH is global for the object, and is searched in its
entirety for each call to process().  You would need multiple
Template::Providers (the piece responsible for turning strings into
file system paths) to implement what you're looking for.

> So, I want to be able to write something like:
> 
> (assume INCLUDE_PATH => '/www/1/html:/www/2/html')
> 
> Within my (mod_perl) script, CWD is /www/2/cgi-bin
> 
> $MyHandler::template->process('../html/results.html',\%vars);

This is correct behavior.  You can modify the INCLUDE_PATH of the
provider, if you have access to the context within your handler:

  sub handler {
      ...

      # This is a nice mouthful...
      
$MyHandler::template->context->load_templates->[0]->include_path(\@new_include_path);

      $MyHandler::template->process("../html/results.html", \%vars);

Assuming that $MyHandler::template isa Template.

If $r->filename is set correctly to /www/X/cgi-bin, then you can do
something tricky like:

    my $path = $r->filename;
    $path = s,cgi-bin.*$,html,;

and use [ $path ] to set INCLUDE_PATH.

> In this case, TT seems to take "results.html" from /www/1/html,
> instead of /www/2/html.

...Because /www/1/html comes before /www/2/html in INCLUDE_PATH.

(darren)

-- 
Nothing worse could happen to one than to be completely understood.
    -- Carl Gustav Jung

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates

Reply via email to