Re: How to iterate items in an object

classic Classic list List threaded Threaded
1 message Options
J Cameron Cooper J Cameron Cooper
Reply | Threaded
Open this post in threaded view
|

Re: How to iterate items in an object

[hidden email] wrote:

> Hi,
> I have a class (say A) which HAS a dictionary of objects which belongs
> to another class (say B)
> The A class IS a plone content type. In my view form, I need to iterate
> the dictionary items in A and get each B type of object and show the
> attributes of B in html.
> Please tell me how to do this with page templating. This seems to be
> very easy in case of JSP, but in case of page templating I'm clueless.
> All the books and examples just describe how to iterate a simple list,
> and they do not answer my complex situation. So finally I decided to put
> viewing logic in python, which is very bad, but I could not help it :-(

It is easy to transform the keys or values of a dictionary into a simple
list. Try it::

  >>> dict = {1:2, 3:4, 5:6}
  >>> dict.values()

The other part of the question is dealing with complex list elements.
This is also straightforward. For each iteration, a new list element is
bound to your repeat variable. Instead of just printing your repeat
variable, ask it for attributes::

  <div tal:repeat="elt context/listOfObjects">
    <div tal:content="elt/getId">Value of attribute of elt</div>
  </div>

I think you can probably manage to put these two together.

                --jcc

--
"It is only by doing things others have not
that one can advance."  - Gen. George S. Patton, Jr.
http://jcameroncooper.com


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users