[ZPT] An easier question ...

Evan Simpson evan@digicool.com
Thu, 31 May 2001 13:33:17 -0500


From: "Lynn Walton" <waltonl@franklin.edu>
> All I had to do was at the top of the slave page put:
> <span tal:define="global arrowMenu string:Current Students"></span>
> before doing the use-macro main bit.
>
> So in essence ... a global variable set will work ....and can just be
accessed by
> it's name without any preceeding template/  or request/ etc.
>
> If any of the ZPT guru's have any comments on whether that is the
"best way" to
> achieve it or if there is a better way, please let me know.

Right now, I think it's the best way to do it.  Since all macro
processing takes place before all TAL processing, from TAL's point of
view there *are* no macros.  This means that variables defined in an
enclosing scope (or previously in the text, in the case of global
variables) can be used inside of used macros, slots, or whatever.  You
can even define a global variable in a macro, then use that variable
below the body of the use-macro, like this:

<div metal:use-macro="here/makes_global/macros/def">Macro Body</div>
<div tal:replace="var_from_macro">Variable from Macro</div>

> when my staff creates a new PT they could set a property on creation,
instead of
> having to be told to always put  something like: <span
tal:define="global

There's been a lot of pressure for PT properties, and your example is a
fine use-case.  It does make me think, though, that rather than the
standard property sheet such as Folders and Documents have (or in
addition to such as sheet), it might be valuable to have a global
variable definition sheet, which would take a form like this (please
excuse ASCII art):

Variable    Expression
______    _____________
|x_____|  |here/foo_______|
______    _____________
|name__|  |string:Fred_____|
______    _____________
|four___|  |python:2+2____|

...and implicitly execute it at the start of page rendering, as though
the first line of the template were:

<div tal:define="global x here/foo;global name string:Fred;global four
python:2+2"></div>

Cheers,

Evan @ digicool