[Templates] INCLUDE context / NAMESPACE

Andy Wardley abw@andywardley.com
Thu, 14 Nov 2002 11:07:34 +0000


Paul Tomlin wrote:
[...]
> what I want to avoid is having to do something like
> 
> [% INCLUDE img.tt2 
> 	src = img1.src
> 	alt = img1.alt
> %]

You could wrap it in a MACRO to make it a little easier to type:

  [% MACRO image(img) INCLUDE img.tt2 src=img.src alt=img.alt %]

  [% image(img1) %]
  [% image(img2) %]

> I am looking at XML::Style but I think that may be limited
> to styles as well.

You could do something like this:

[% USE xmlstyle 
     img1 = {
         element    => 'img',
         attributes => {
             src = img1.src
             alt = img1.alt
         }
     }
%]

Filter your documents through xmlstyle and any tags like:

  <img1 />

will be converted into

  <img src="blahblah.gif" alt="blah blah" />


A