[Templates] INCLUDE context / NAMESPACE

Paul Tomlin paul@digitlondon.com
Wed, 13 Nov 2002 17:45:33 -0000


Hi,
I have a number of small templates, basically reflecting
HTML elements. ie:

<p style="[% style %]">$content</p>

and 

<div style="[% style %]">$content</div>


Now, in my outer template I can do something like

[% WRAPPER p.tt2 %]
This is paragraph text
[% END %]

[% WRAPPER div.tt2 %]
This is div text
[% END %]

If I have a 'style' variable, it obviously uses it
for both cases. I want to be able to have a
variable structure like

$vars = {
	div1 => {
		style => 'color: white;',
	},
	div2 => {
		style => 'color: blue;',
	},
	p1 => {
		style => 'colour: red;',
	},
};

and then have the template do something like

[% INCLUDE div.tt2 CONTEXT = div1 %]
[% INCLUDE div.tt2 CONTEXT = div2 %]
[% INCLUDE div.tt2 CONTEXT = p1 %]

to produce 

<div style="color: white;">..</div>
<div style="color: blue;">..</div>
<div style="color: red;">..</p>

Essentially what I want to do is have the stash (?) for
the INCLUDEd block to start at a given variable.

Oh, to explain to obvious question, my outer templates
are being generated dynamically and reusing either other
dynamic templates, or the basic static ones like above.

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.

Paul