Hi all, 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> to set a default value for dn. However I can't quite figure out how to set default values for vars in a ZPT page. The best I've come up with so far is this: <span metal:fill-slot="userList_slot" tal:content="structure python:here.userList(dn=request.dn)" tal:on-error="structure python:here.userList(dn=None)">User List goes here</span> Which is fine if there is only one var but what if there are more? Any ideas? Phil phil.harris@zope.co.uk
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
participants (2)
-
Evan Simpson -
Phil Harris