<span tal:define="global foo python:[{'a':1},{'a':2}]"></span> <span tal:repeat="v foo"> <span tal:content="repeat/v/a"></span> </span> The code above doesn't work. Instead, I have to replace the content= with "python:foo[repeat['v'].index]['a']" Seems silly and cumbersome. Am I doing something stupid here (like forgetting the python syntax for creating objects on the fly so I can use a list of objects instead of a list of dictionaries)? Argh. Going back and forth between JavaScript, Python, Perl and Java is killing me. aathan <Andrew Athan>
Evan: This, unfortunately, does not work. It yields the error "global name 'a' is not defined" The issue is that dictionary keys do not seem to be traversible as attributes. So what I need to be creating in the tal:define is a dictionary that has a __getattr__ function I guess?? A. -----Original Message----- From: Evan Simpson [mailto:evan@4-am.com] Sent: Tuesday, November 05, 2002 2:19 PM To: Andrew Athan; zope@zope.org Subject: Re: tal:repeat usage Andrew Athan wrote:
<span tal:define="global foo python:[{'a':1},{'a':2}]"></span>
<span tal:repeat="v foo"> <span tal:content="repeat/v/a"></span> </span>
Use "v/a" instead of "repeat/v/a". Cheers, Evan @ 4-am
Andrew:
Evan:
This, unfortunately, does not work. It yields the error "global name 'a' is not defined"
The issue is that dictionary keys do not seem to be traversible as attributes. So what I need to be creating in the tal:define is a dictionary that has a __getattr__ function I guess??
... or simpler use tal:repeat="python:v['a']" In my opinion python expressions would make better defaults than path expressions anyway, as one does not run into the limitations of path expressons every now and then. (This is not a serious proposal, of course; I just do not like one line replies ;-) Cheers, Clemens
A.
-----Original Message----- From: Evan Simpson [mailto:evan@4-am.com] Sent: Tuesday, November 05, 2002 2:19 PM To: Andrew Athan; zope@zope.org Subject: Re: tal:repeat usage
Andrew Athan wrote:
<span tal:define="global foo python:[{'a':1},{'a':2}]"></span>
<span tal:repeat="v foo"> <span tal:content="repeat/v/a"></span> </span>
Use "v/a" instead of "repeat/v/a".
Cheers,
Evan @ 4-am
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Andrew Athan wrote:
This, unfortunately, does not work. It yields the error "global name 'a' is not defined"
The issue is that dictionary keys do not seem to be traversible as attributes.
I just tried it, and it worked fine for me. If I use "v/blah" instead, I get a KeyError; I can't replicate your "global name..." error. Here's the whole thing: <span tal:define="global foo python:[{'a':1},{'a':2}]"></span> <span tal:repeat="v foo"> <span tal:content="v/a"></span> </span> Cheers, Evan @ 4-am
Yes, it sure does work. My apologies, perhaps I made some kind of typo when I tested your suggestion. Removing foot from mouth, A. -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Evan Simpson Sent: Tuesday, November 05, 2002 4:02 PM To: Andrew Athan Cc: zope@zope.org; robbenhaar@espresto.com Subject: [Zope] Re: tal:repeat usage Andrew Athan wrote:
This, unfortunately, does not work. It yields the error "global name 'a' is not defined"
The issue is that dictionary keys do not seem to be traversible as attributes.
I just tried it, and it worked fine for me. If I use "v/blah" instead, I get a KeyError; I can't replicate your "global name..." error. Here's the whole thing: <span tal:define="global foo python:[{'a':1},{'a':2}]"></span> <span tal:repeat="v foo"> <span tal:content="v/a"></span> </span> Cheers, Evan @ 4-am _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Andrew Athan -
Andrew Athan -
Clemens Robbenhaar -
Evan Simpson