[ZPT] tal:define limitations

Michael Bernstein webmaven at lvcm.com
Sat Oct 18 18:31:24 EDT 2003


(Reposted from main zope at zope.org list)

I just stumbled across the fact that variables that are defined via 
tal:define apparently must conform to Python identifier conventions 
(must start with a letter or underscore, etc.). This doesn't seem to be 
mentioned anywhere in the documentation.

However, URL arguments and form field names are not subject to the same 
limitations at all, which leaves me with no simple way to define default 
values in TAL for optional URL arguments or form fields that use a 
number as the identifier for a name/value pair.

Example:

http://example.com/sample?1=off

I would like the following code to work:

<html tal:define="1 request/1 | string:on">

This should have the effect of defaulting the argument to 'on' within 
the context of the page when the URL is http://example.com/sample but 
allowing it to be overridden via the URL parameter 1=off.

However, when adding similar code to a Page Template, I get an error:

Compilation failed
TAL.TALDefs.TALError: invalid define syntax: '\n       1 request/1 | 
string:on', at line 7, column 3

My use-case is simple presentation logic, but this mismatch between 
allowable URL and form names on the one hand and allowable tal:define 
variables on the other is inconvenient, to say the least.

Questions:

- Is there another way of doing this simply (more simply that populating 
the REQUEST directly with a python expression or script)?

- Should the restrictions on tal:define variable names be relaxed?


Thanks in advance,

- Michael Bernstein




More information about the ZPT mailing list