[Templates] INCLUDE context / NAMESPACE

Paul Tomlin paul@digitlondon.com
Thu, 14 Nov 2002 11:32:50 -0000


But in reality an IMG element has (at least) 24
attributes, some other elements have many more,
which is a lot of fairly redundent code.

I was just looking at the Plugin::HTML docs and this
is something like the functionality I am looking for
except that I want to be able to create 'elements' which
are in fact BLOCKs

I have just tried to example my idea but found it came down
to a problem 'identifying' elements within BLOCKs. I'll
come up with a sensible way to address elements which will
help to explain the goal.

-----Original Message-----
From: Andy Wardley [mailto:abw@ourshack.com]On Behalf Of Andy Wardley
Sent: 14 November 2002 11:08
To: Paul Tomlin
Cc: templates@template-toolkit.org
Subject: Re: [Templates] INCLUDE context / NAMESPACE


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