iterating dictionaries with dtml-in
Hi, I know it's a silly question. But I was not able to find an example for this: I have a list of dicts like [ {'name':'John','age':27}, {'name':'Marc','age':17}, {'name':'Susanne','age':19} ] Now I want to iterate each 'name' like <select> <option>John</option> <option>Marc</option> <option>Susanne</option> </select> I want to do this with DTML. <select> <dtml-in getDicts> <option> HOW CAN I PUT the keys 'name' HERE ???? </option> </dtml-in> </select> (getDicts returns the above list of dictionaries) Thanks and greets, Ferhat __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
----- Original Message ----- From: "Ferhat Ayaz" <ferhatayaz@yahoo.com> To: <zope@zope.org> Sent: Saturday, September 02, 2006 7:40 AM Subject: [Zope] iterating dictionaries with dtml-in
Hi, I know it's a silly question. But I was not able to find an example for this:
I have a list of dicts like [ {'name':'John','age':27}, {'name':'Marc','age':17}, {'name':'Susanne','age':19} ]
Now I want to iterate each 'name' like <select> <option>John</option> <option>Marc</option> <option>Susanne</option> </select>
I want to do this with DTML.
<select> <dtml-in getDicts> <option> HOW CAN I PUT the keys 'name' HERE ???? </option> </dtml-in> </select> (getDicts returns the above list of dictionaries)
If getDicts returns a list of python dictionaries then you are going to require an outer loop (to run thru the list) and an inner loop (to run thru the keys of the current dictionary). Something like this will get you going in the right direction: <dtml-let dictList="getDicts"> <dtml-in dictList prefix=aDict> <dtml-in "aDict_item.keys()"> <dtml-var sequence-item>, <dtml-var "aDict_item[_['sequence-item']]"> </dtml-in> </dtml-in> </dtml-let> However, it would be much easier to change your getDicts routine to format the data you need for your OPTION statements, instead of extracting this information via dtml. hth Jonathan
Ferhat Ayaz wrote at 2006-9-2 04:40 -0700:
... I want to do this with DTML.
<select> <dtml-in getDicts> <option> HOW CAN I PUT the keys 'name' HERE ???? </option> </dtml-in> </select> (getDicts returns the above list of dictionaries)
You probably need the "mapping" attribute of "dtml-in" -- and maybe some background reading (you should read the documentation (Zope Book 2.7 edition, online on plope.org). -- Dieter
Dieter Maurer wrote:
Ferhat Ayaz wrote at 2006-9-2 04:40 -0700:
... I want to do this with DTML.
<select> <dtml-in getDicts> <option> HOW CAN I PUT the keys 'name' HERE ???? </option> </dtml-in> </select> (getDicts returns the above list of dictionaries)
You probably need the "mapping" attribute of "dtml-in" -- and maybe some background reading (you should read the documentation (Zope Book 2.7 edition, online on plope.org).
Ferhat, If you are new to Zope do yourself a favor and forget about DTML. Yeah its fun and (seemingly) easy to learn. But I argue for Page Templates + python. Python is so much clearer than dtml - and Page Templates + python *is* the favored zope paradigm. But if you insist - Casey Duncan wrote a nice product (dtml-eval) and an interesting discussion about DTML and what to watch out for ... http://www.zope.org/Members/Kaivo/EvalTag_HowTo
Thank you for your suggestion. Indeed, I noticed that page templates are great. I can code my websites now fastern then with any other alternative. I'm also using Dreamweaver to design the pages. It's just great and its working without problems. Accessing dictionaries are nativly supported by page templates. I'm reading the zope book 2.7 (plope.org) now. I read the 2.7 before. Greets, Ferhat --- David H <bluepaul@earthlink.net> wrote:
Dieter Maurer wrote:
Ferhat Ayaz wrote at 2006-9-2 04:40 -0700:
... I want to do this with DTML.
<select> <dtml-in getDicts> <option> HOW CAN I PUT the keys 'name' HERE ???? </option> </dtml-in> </select> (getDicts returns the above list of dictionaries)
You probably need the "mapping" attribute of "dtml-in" -- and maybe some background reading (you should read the documentation (Zope Book 2.7 edition, online on plope.org).
Ferhat,
If you are new to Zope do yourself a favor and forget about DTML. Yeah its fun and (seemingly) easy to learn. But I argue for Page Templates + python. Python is so much clearer than dtml - and Page Templates + python *is* the favored zope paradigm.
But if you insist - Casey Duncan wrote a nice product (dtml-eval) and an interesting discussion about DTML and what to watch out for ...
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (4)
-
David H -
Dieter Maurer -
Ferhat Ayaz -
Jonathan