[ZPT] Globals from calling script

Dieter Maurer dieter at handshake.de
Sat Dec 20 07:30:49 EST 2003


Philip Kilner wrote at 2003-12-19 13:16 +0000:
>I have a script which is calling a ZPT containing a form. The form 
>submits to ".", which I understand to mean "me"

This is wrong. "." means the parent. "" means the same document
but this is handled wrong by many browsers in some circumstances.
Thus, do not rely on it.

> ...
>If there are no errors, the script calls another ZPT. If there are 
>errors, the script puts them in a dictionary and re-calls the first ZPT.
>
>My problem is that I can't figure out how to display my dictionary in 
>the ZPT - whatever I try, I get either a "key error" or a "global not 
>defined".
>
>The ZPT does not seem to have access to the same name space as the 
>script,

This is indeed the case (and very wide spread in programming).

>and if I use tal:define global I seem to be wiping out my 
>dictionary. I'd naively though that by calling the ZPT from the script I 
>had a single "environment".

Such a techique is called dynamic binding and is highly error prone.
Most (compiled) programming languages use static bindung:

  You can determine which variables are visible by looking (statically)
  at the code. It is not relevant how the function was called.

Python is such a language.

You must pass your dictionally as argument to your ZPT.
Inside the ZPT, you can access it via the predefined
"options" variable. Read the Zope Book, for details...

-- 
Dieter



More information about the ZPT mailing list