[Zope] Re: Passing arguments to a ZPT
Maik Jablonski
maik.jablonski@uni-bielefeld.de
Sat, 22 Mar 2003 12:09:41 +0100
Johan Carlsson [EasyPublisher] wrote:
> Short version: How do I access keyword arguments passed to a ZPT?
Have a look at "options" as access-point to keyword-arguments... Taken
from the ZopeBook
(http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AdvZPT.stx):
"""The action script can do all kinds of things. It can validate input,
handle errors, send email, or whatever it needs to do to "get the job
done". Here's a sketch of how to validate input with a script:
## Script (Python) "action"
##
if not context.validateData(request):
# if there's a problem return the form page template
# along with an error message
return context.formTemplate(error_message='Invalid data')
# otherwise return the thanks page
return context.responseTemplate()
This script validates the form input and returns the form template with
an error message if there's a problem. The Script's context variable is
equivalent to here in TALES. You can pass Page Templates extra
information with keyword arguments. The keyword arguments are available
to the template via the options built-in variable. So the form template
in this example might include a section like this:
<span tal:condition="options/error_message | nothing">
Error: <b tal:content="options/error_message">
Error message goes here.
</b></span>
This example shows how you can display an error message that is passed
to the template via keyword arguments. Notice the use of | nothing to
handle the case where no error_message argument has been passed to the
template."""
HTH,
-mj