[Zope] including a ZPT inside a repeat loop
Chris Withers
chris at simplistix.co.uk
Wed Sep 28 04:59:42 EDT 2005
Matthew White wrote:
> oops! I thought I'd clean up my code snippet to make it a little more
> readable, and instead introduced an error. Here it is in full:
>
> <tal:loop repeat="t python:test(exists('/request/form/view_all'),
> container.py.new_get_queue(whence=q),
> container.py.new_get_queue(whence=q, userid=userid))">
As another thing here, the above is pretty expensive, since you call
new_get_queue twice, whatever happens, how about the following:
<tal:loop repeat="t python:container.py.new_get_queue(
whence=q,
userid=request.form.get('view_all') and \
userid or None))">
..and then make new_get_queue do the right thing when it gets None as
userid.
I'd probably also change the following to be a metal: macro include
rather than calling the second template.
>
> <span tal:replace="structure here/queue_template">
> Queue Template Goes Here
> </span>
As a general comment, you're trying to do too much logic in ZPT here, do
much more work in a class or python script and just return the stuff you
want to display to the ZPT...
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope
mailing list