[Templates] INCLUDE context / NAMESPACE

Paul Tomlin paul@digitlondon.com
Thu, 14 Nov 2002 10:55:09 -0000


Actually my BLOCKS include all HTML 4.0 attributes for
all the non-depreciated elements. I simply chose style
as an example. It might have been an IMG element
and I wanted to set the SRC attribute..

<img src="[% src %]" alt="[% alt %]" longdesc="[% longdesc %] ... />

what I want to avoid is having to do something like

[% INCLUDE img.tt2 
	src = img1.src
	alt = img1.alt
%]

I guess that if the element BLOCKs are like

<img src=[% context.src %] />

I can then do

[% INCLUDE img.tt2 content = img1 %]

but I was, and still am looking for something 'cleaner'.

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

I saw a thread in the archives about implementing DO as a
template command which was INCLUDE with a new stash, I'm looking
for INCLUDE with a segment of the stash.

-----Original Message-----
From: templates-admin@template-toolkit.org
[mailto:templates-admin@template-toolkit.org]On Behalf Of Andrew
McFarland
Sent: 14 November 2002 08:42
To: Paul Tomlin; templates@template-toolkit.org
Subject: Re: [Templates] INCLUDE context / NAMESPACE


At 17:45 13/11/2002 +0000, "Paul Tomlin" <paul@digitlondon.com> wrote:
<snip>
 >Any ideas? I'm sure that there is probably a way to achieve
 >what I want but it may not be in the way I am expecting.
<snip>

I think a lot of what you want can be achieved outside of TT.

Don't use the style attribute in production code - it causes all sorts of 
weird problems[0]. Use an external CSS[1] file and the class attribute. 
Then use rules in the CSS like this:

p.styled {color: red}

div.styled {color: blue}

Using more complex CSS rules, and a properly structured (X)HTML document, 
you can probably get all the styling you need[2]. In fact if you do it 
really properly you may even be able to avoid the class attribute 
altogether.

If you really want to do it in TT, something like

$context = {
    bat => "cool"
};

[% PROCESS foo bar=bat %]

[% BLOCK foo%]
<div class="[% context.${bar} %]">
[% END %]

may be what you want, but I'll let TT experts comment on that one.

[0] See http://aamcf.co.uk/temp/botch in Netscape 4 with CSS on for an 
extreme example.
[1] Assuming you are using CSS
[2] E-mail me offlist for tips if you need to. Its way OT for here :)
--
Andrew McFarland
UNITE Solutions          Phone 028 9077 7338
http://www.unite.net/    Fax   028 9077 7313


_______________________________________________
templates mailing list
templates@template-toolkit.org
http://lists.ourshack.com/mailman/listinfo/templates