Bill Moseley wrote:
It would be somewhat handy if simply "PROCESS footer" would also look in the
current directory. That is, the current template's directory is
shifted onto INCLUDE_PATH.
Hi Bill,
I've been scratched by that itch many times myself. I daren't change
the behaviour in TT2 but something like that it is already implemented
in the TT3 codebase.
For TT3 we've thrown away the (all but useless) RELATIVE and ABSOLUTE
options.
Relative paths will be resolved according to the location of the current
template.
e.g. in product/widget/index.html:
[% INCLUDE ./header %] # product/widget/header
[% INCLUDE ../header %] # product/header
[% INCLUDE ../../header %] # header
We've also got "walkup" and "walkdown" paths which look for the file in
any of the directories leading up/down to the current template location.
[% INCLUDE .../header %] # product/widget/header,
# product/header or
# header
[% INCLUDE /.../header %] # header,
# product/header or
# product/widget/header
Note that you can only resolve as far up as the INCLUDE_PATH roots and
no further. i.e. you can't do this:
[% INCLUDE ../../../../../../../../../etc/passwd %]
Well, you can, but you'll end up with the same thing as /etc/passwd
which is the same thing as just etc/passwd. This is because absolute
paths will be treated as relative to the INCLUDE_PATH (or template_path
as it will most likely be known in TT3).
[% INCLUDE /etc/passwd %] # /dir/on/include/path/etc/passwd
If you want to emulate the behaviour of the TT2 ABSOLUTE option (to
access a file in your filesystem root) then you just have to add '/' to
your template_path.
For a short-term TT2 solution, the following MACRO does a quick-n-dirty
job of generating a relative path from the current component path
[% MACRO relative(path)
GET component.name.remove('[^/]+$') _ path;
%]
[% INCLUDE $relative('example') %]
Cheers
A
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates