Chuck Adams <[EMAIL PROTECTED]> said something to this effect on 10/30/2001: > > * For historical reasons, our HTML developers require that > > files that are INCLUDEd or PROCESSed be searched for in a > > tree-walking manner, starting with the directory of > > $r->filename and ascending to /. This has the effect of > > including the closest copy of files declared in TT2PreProcess > > and TT2PostProcess, which works out very well for using a > > single set of header and footer files for an entire site, > > while having section specific navigation bars and features > > that get included without having to specify paths and the > > like. > > Yep, that's precisely the behavior I'm looking for, though not > exactly with $r->filename, but the location of the current > template doing the loading -- or, based on some policy rule or > metadata, another location, for that template, reverting to > standard behavior when that template's processing exits (thus > the document stack). Mason's behavior is to rewrite the > filename to dhandler then search for dhandler in that fashion, > which is a behavior I want to be able to implement as well, > even if I don't see myself actually using it. Anyway, having > that level of flexibility would indicate the use of a Strategy > pattern.
That's exactly the functionality _inc_path provides. It takes a filename as a (string) argument, so it is not required to be $r->filename -- it can be anything filepath-ish. And, as Perrin suggested, if you use File::Spec, then your definition of "filepath-ish" can be pretty generic. Keep in mind that in my module, from which _inc_path was taken, $r->filename *is* the location of the current template. > > INCLUDE_PATH = /foo:/bar+ > > > > If the main template is 'abc/def/ghi.tt2' which gets resolved as > > '/foo/abc/def/ghi.tt2' and includes a directive like [% INCLUDE xyz > > %] > > then it should look for: > > > > /foo/xyz > > /bar/xyz > > /bar/abc/xyz > > /bar/abc/def/xyz > > > > Yes, but what if the document requested is for > /mumble/frotz/plugh.tt2 and it does [% INCLUDE abc %]. I would > want it to search /mumble/frotz and /mumble as well, even > though they are not in the INCLUDE_PATH. That would be > consistent with the behavior of searching the directory of > $r->filename down to /. *nod*. That is exactly what we needed as well. I personally don't like the idea of searching down the path; searching up gives the illusion of hierarchy, which is what many web designers are going for anyway. Searching both up and down a path leads to precedence issues, as well, which can get pretty hairy when you start wanting the direction to vary with each call to process. Let me know if you are interested in taking a look at the code to which I keep referring. (darren) -- All is fear in love and war.
