[Templates] filtering includes

Simon Wilcox essuu@ourshack.com
05 Nov 2002 12:26:00 +0000


On Tue, 2002-11-05 at 12:10, Rafiq Ismail (ADMIN) wrote:
> Hi Templatinos,
> 
> I'm looking for an easy way to solve a problem, which I'm currently
> facing.  We have a HUGE bunch of default html_header, footer, etc files
> which tie into our legacy non-template system.  They are all raw html with
> the exception of a couple of unconventioanl strings which get substituted
> into, in order to provide link uri's.
> 
> I initially wanted to just INCLUDE these files however, this wouldn't take
> care of the whole string substitution problem.  My untidy wrapper for this
> was to write a plugin which did the file read and 'drop' into the
> template. There are some extra checks such as picking up a default
> language file where the i18n supported file doesn't exist.

You could use INSERT in your templates to read in the html. This would
be faster than INCLUDE but only works if you have no TT directives in
the files.

To do the substitution I would use a FILTER on the assembled output.
This is what I'm currently writing to handle the munging of img tags.

I have a wrapper.tt which is processed for every template. It looks
like:

[%- WRAPPER page.tt; PROCESS $template; END %]

I plan to change it to:

[%- FILTER FilterImg; WRAPPER page.tt; PROCESS $template; END; END %]

So that all my img tags get the correct attributes for height and width
and enforce a default alt attribute.

Something similar might work for you.

Simon.