including a ZPT inside a repeat loop
Hello, I've got this following bit of ZPT: <tal:loop repeat="t container.py.get_queue(whence=q, userid=userid))"> <span tal:replace="structure here/queue_template"> Queue Template Goes Here </span> within queue_template I reference the "t" loop variable. Unfortunately this fails with a KeyError, which I'm guessing is because "t" isn't available to the "queue_template" ZPT. Is there a way to make "t" available to "queue_template"? -mtw -- Matthew White - District Systems Administrator Tigard/Tualatin School District 503.431.4128 "The greatest thing in this world is not so much where we are, but in what direction we are moving." -Oliver Wendell Holmes
On 27 Sep 2005, at 17:02, Matthew White wrote:
Hello,
I've got this following bit of ZPT:
<tal:loop repeat="t container.py.get_queue(whence=q, userid=userid))">
<span tal:replace="structure here/queue_template"> Queue Template Goes Here </span>
you're using a python notation without declaring it as such. Try... <tal:loop repeat="t python: container.py.get_queue(whence=q, userid=userid)"> jens
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))"> <span tal:replace="structure here/queue_template"> Queue Template Goes Here </span> On Tue, Sep 27, 2005 at 05:04:39PM +0100, Jens Vagelpohl (jens@dataflake.org) wrote:
On 27 Sep 2005, at 17:02, Matthew White wrote:
Hello,
I've got this following bit of ZPT:
<tal:loop repeat="t container.py.get_queue(whence=q, userid=userid))">
<span tal:replace="structure here/queue_template"> Queue Template Goes Here </span>
you're using a python notation without declaring it as such. Try...
<tal:loop repeat="t python: container.py.get_queue(whence=q, userid=userid)">
jens
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Matthew White - District Systems Administrator Tigard/Tualatin School District 503.431.4128 "The greatest thing in this world is not so much where we are, but in what direction we are moving." -Oliver Wendell Holmes
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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))">
<span tal:replace="structure here/queue_template"> Queue Template Goes Here </span>
Names defined in one template are only available within that template, or within macros it inlines. Your case *calls* the second template, and so would need to pass 't' along explicitly, e.g.: <span tal:replace="structure python:here.queue_template(t=t)" /> In that case, the 'queue_template' script would use 'options/t' to get to the passed value, e.g:: <div> <h1 tal:content="options/t">T</h1> </div> An alternative spelling would be to add a 'metal:define-macro="qt"' attribute to your 'queue_template', and then include it as a macro, e.g.: <!-- In 'queue_template'; expects to find the name 't' bound in the TAL namespace. --> <div metal:define-macro="qt"> <h1 tal:content="t">T</h1> </div> and:: <span metal:use-macro="here/queue_template/macros/qt" /> Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDOXsa+gerLs4ltQ4RAhZiAJ4h+15swFdO/F06QI+Zc5ULZcFACgCgmYT2 BeTqOab8BRcM5+gtK2+6Xlk= =9iF+ -----END PGP SIGNATURE-----
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
participants (4)
-
Chris Withers -
Jens Vagelpohl -
Matthew White -
Tres Seaver