Andy Wardley <[EMAIL PROTECTED]> writes: > Chris Ochs wrote: >> I'm trying to pull in a header.html file from the same directory using this: >> >> [% PROCESS './header.html' %] > > I see you've already discovered why this isn't working as expected. > '.' refers to the current working directory and is entirely unrelated > to wherever the template came from. > > I think this has to be one of the most useless and badly conceived > features in TT. Why on earth I made it like that I will never know. > > I'm fixing it in TT3. The problem in TT2 is that templates don't know > where they came from. [...]
I am fighting the same problem, and I've written a quick and dirty plugin to work around this: I am interpreting template names as URLs in a non-existing "TT scheme". Though templates don't know where they came from in a file system's sense, they still could have some concept about "../" in their template.name and component.name variables. This is especially true for ttree produced sites. If, for example, template.name is 'site/owner/tt.tt2', then "../navigation.tt2" can be rather unambiguously mapped to 'site/navigation.tt2', and '/navigation.tt2' would just be what [% INCLUDE navigation.tt2 %] is today. And, finally, 'navigation.tt2' is 'site/owner/navigation.tt2'. I'm using this to walk up to the root, in two ways: - find the first file upward called 'navigation.tt2', and process it, - find *all* files upward called 'profile.tt2', and process them all (using TRY/CATCH blocks to deal with non-existing files on the path). As a bonus, using the same technique I can write relative links into my navigation.tt2 files and the plugin correctly inserts the correct number of '../'s, even if they are being called from templates in deeply nested directories. And I can guess whether a link points to the file currently processed if I want to apply a special style to it. I have almost forgotten about the details because I haven't touched the (undocumented) plugin for about two years now. If someone finds it useful, I might be able to dig into it again (it's barely 100 lines of code). -- Cheers, haj _______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates