Re: [Zope] Referencing Objects from id's stored in a lines property. -- Yet Another Update
I'm considering using a DTML document having a lines property that stores id's of related objects (i.e., objects where there is to be a user-defined relation). Essentially, the lines property would be a container of id's of objects available to the object having the lines container. I can load the id's into the lines property (that is easy). However, does anyone know of the DTML code needed to sequentially list each of the elements in the lines property (which is a Python list) and then call that object to obtain and then display the title corresponding to the object id? The following code works... <P>Here they are, one by one.<BR> <dtml-in cases> <A HREF="<dtml-var sequence-item>"><dtml-var sequence-item></A><BR> </dtml-in> But the above code only lists the id's, not the titles to the id's (which would be easier for the user to understand). I tried this... <P>Here they are, one by one.<BR> <dtml-in my_related_objects> <A HREF="<dtml-var sequence-item>"><dtml-var expr="getattr(sequence-item, 'title')"></A><BR> </dtml-in> .. but got a parsing error. Then I tried this... <P>Here they are, one by one.<BR> <dtml-in cases> <A HREF="<dtml-var sequence-item>"> <dtml-let my_id=sequence-item> <dtml-in objectValues(my_id)> <dtml-var title> </dtml-in> </dtml-let> </A><BR> </dtml-in> .. but that didn't work either. (Error message). Incidentally, ... <P>Here they are, one by one.<BR> <dtml-in cases> <A HREF="<dtml-var sequence-item>"> <dtml-let my_id=sequence-item> <dtml-in expr="objectValues(my_id)"> <dtml-var title> </dtml-in> </dtml-let> </A><BR> </dtml-in> .. didn't work either. In this case, however, the code ran properly (no error messages). Unfortunately, it didn't display any of the titles. This is a copy of the resulting HTML code. <P>Here they are, one by one.<BR> <A HREF="pto_test"> </A><BR> <A HREF="test_url"> </A><BR> Does anyone know what I did wrong? Is there a better way to do this? Thanks again, Ron
Hey Ron, complaw@hal-pc.org wrote:
I'm considering using a DTML document having a lines property that stores id's of related objects (i.e., objects where there is to be a user-defined relation). Essentially, the lines property would be a container of id's of objects available to the object having the lines container.
I can load the id's into the lines property (that is easy). However, does anyone know of the DTML code needed to sequentially list each of the elements in the lines property (which is a Python list) and then call that object to obtain and then display the title corresponding to the object id?
The following code works...
<P>Here they are, one by one.<BR> <dtml-in cases> <A HREF="<dtml-var sequence-item>"><dtml-var sequence-item></A><BR> </dtml-in>
But the above code only lists the id's, not the titles to the id's (which would be easier for the user to understand).
Ok you're close. <dtml-in cases> <A HREF="<dtml-var sequence-item>"><dtml-var expr="_.getitem(_['sequence-item']).title"></A><BR> </dtml-in> The key is that the sequence-item has the id as a string, so you need to get the item that the id refers to out of the _ namespace. Actually this code is a little nastier than it needs to be because of a (soon-to-be-fixed?) problem with name "sequence-item". The following code also works <dtml-in cases> <dtml-let sequence_item="_['sequence-item']"> <A HREF="<dtml-var sequence_item>"><dtml-var expr="_.getitem(sequence_item).title"></A><BR> </dtml-let> </dtml-in> the embedded '-' in sequence-item means we have to use the _['sequence-item'] whenever we drop down into expression. hope that helps -- Tom Jenkins devIS - Development Infostructure http://www.devis.com
participants (2)
-
complaw@hal-pc.org -
Tom Jenkins