>From time to time I see people requesting allowing finding templates relative
to the current template. I just responded to an email this morning with how
to do so in Template::Alloy. I would propose having it as an option in
Template::Toolkit.
If ADD_LOCAL_PATH is set, then whenever a file is being processed, the
INCLUDE_PATHS variable is locally modified to include the current path.
There is no speed hit for cases when ADD_LOCAL_PATH is not set. See the
Template::Alloy pod page for the ADD_LOCAL_PATH configuration option for more
information.
This actually can provide a certain degree of magic, if for example, a
standard header is used that includes a chunk "logo.html" - each directory
could use the same standard header - but have its own logo.html - and it just
works.
Paul Seamons
The following is an example of this in action that I sent in an email this
morning.
Template::Toolkit doesn't offer this yet (but hopefully will) - but TA does:
use Template::Alloy;
use POSIX qw(tmpnam);
use File::Path qw(rmtree mkpath);
my $dir = tmpnam;
mkpath($dir);
mkpath("$dir/dir2");
END { rmtree $dir };
open(my $fh, ">", "$dir/foo.tt");
print $fh "I am foo.tt";
open $fh, ">", "$dir/dir2/bar.tt";
print $fh 'I am bar.tt
------------
[% PROCESS "../foo.tt" %]
';
close $fh;
my $ta = Template::Alloy->new(
INCLUDE_PATH => $dir,
RELATIVE => 1,
ADD_LOCAL_PATH => 1);
$ta->process("dir2/bar.tt") || die $ta->error;
The ADD_LOCAL_PATH configuration item is what does it.
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates