[Zope] ZPT - equivalent of dtml-unless

Evan Simpson evan@4-am.com
Fri, 22 Jun 2001 18:01:38 -0400


Phil Harris wrote:

> I have a ZPT page which can optionally get a parameter, dn, which gets used
> in a call to a Script (Python).
> 
> If I was doing this with DTML, I would use something like,
> 
> <dtml-unless dn>
>   <dtml-call "REQUEST.set('dn','o=cm')">
> </dtml-unless>


Quick note - you're more likely to get responses on the ZPT mailing 
list.  On to the question:

tal:define="dn_def string:o=cm; dn request/dn | dn_def"

...will set 'dn' equal to the request form value if it exists, otherwise 
to the string "o=cm".  You can extend this to deal with keyword 
arguments to the template, like so:

tal:define="dn_def string:o=cm; dn options/dn | request/dn | dn_def"

...and of course, if the default value is accessible as a path, there's 
no need for the two-step:

tal:define="dn request/dn | here/dn_property"

Finally, if you want to use a Python expression, you can do:

tal:define="dn python:path('request/dn') or 'o=cm'"

Cheers,

Evan @ digicool