[ZPT] global variables and ZPT

Schmidt, Amy ASchmidt@arn.com
Sat, 3 Nov 2001 21:02:34 -0500


Evan,
You helped me fix a major error in the way I was building my zope
application - I was embedding page templates as content. I really should
have been using METAL - not TAL - to reference the child/content page
templates. So, now that my page templates use METAL, I am running into my
first difficulty with learning macros. I define a property named "phase" in
my container page template. Then I call a macro with some content. Inside
that macro, I need to able to able to reference the value of the "phase"
property I set in the containing page template. I have tried various
syntaxes with no luck. I thought the following would work:
<span tal:define="global phase template/phase"></span>

What am I missing? Thanks again, AMY

-----Original Message-----
From: Evan Simpson
To: Schmidt, Amy
Cc: 'zpt@zope.org'
Sent: 11/2/01 11:47 AM
Subject: Re: [ZPT] global variables and ZPT

Schmidt, Amy wrote:

> I have a main page template that contains references to other page
> templates. So my main page template is basically a container page and
the
> referenced page templates are child pages. I need to set a variable in
the
> container page that can be accessed by its children.


How are the "children" referenced?  Like tal:replace="structure
here/child"?
Or like metal:use-macro="here/child/macros/block"?

When you use a macro, the macro body automatically sees all variables 
defined in the enclosing scope.  When you embed a page template as
though it 
were content, you need to explicitly pass variables that you want it to 
have, either like this:

PT1: <div tal:replace="structure python:here.PT2(foo=foo,
bar=bar)"></div>
PT2: <span tal:replace="options/foo">Foo</span>

...or like this:

PT1: <div tal:define="x python:request.set('foo', foo),
request.set('bar', 
bar)" tal:replace="structure here/PT2"></div>
PT2: <span tal:replace="request/foo">Foo</span>

In the first case, you pass the values as keyword arguments, and in the 
second you stuff them into the request.

I suspect that macros might make your like easier, since their entire 
purpose is enabling shared presentation elements.

Cheers,

Evan @ Zope