Display Contents of Item in Object Relation List

Author Message

Alex Jones

Saturday 14 February 2004 11:08:24 am

How can I display the contents of any related items in a template? For example, I have set up an Info Page which lists some contact information, I would like to add this to another page (we'll call it Company Info) via the ORL. So, what code do I need to insert in the page template for Company Info to ensure the information is displayed on that page? I've tried multiple methods and can't seem to get it to work. I am using 3.3.2.

Your help is truly appreciated!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Alex Jones

Wednesday 05 May 2004 1:50:29 pm

Anyone?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Thursday 06 May 2004 1:14:13 am

Hi Alex,

Is this what you are after?

{default content_object=$node.object
         content_version=$node.contentobject_version_object}

{section loop=$content_version.data_map.related_objects.content.relation_list}

        {set relation_object=fetch(content,object,hash(object_id,$:item.contentobject_id,
                                                       object_version,$:item.contentobject_version))}

        {* Test for some class *}
        {section show=eq($relation_object.contentclass_id, $contact_us_class_id)}
                 {content_view_gui view=full content_object=$relation_object}
        {/section}

{/section}

{/default}

paul

--
http://www.visionwt.com

Alex Jones

Thursday 06 May 2004 6:22:06 am

Thanks for the reply Paul. That doesn't seem to do the trick. Perhaps I have an odd setup: I have extended the <i>Info Page</i> class by adding an <i>Object Relation List</i> to it. The <i>ORL</i> is named "Additional Images" (additional_images). What I would like is for the display loop through all of the images that may have been associated via the <i>ORL</i> and display them. I will also have another <i>ORL</i> to include text like contact info. Again, I will want this embedded in the page. At the moment I am testing with the images and am able to get a link to display when using <i>{attribute_view_gui attribute=$node.data_map.additional_images}</i>. I was hoping there was a simple way to embed the info, but I think I will have to set up a fetch loop like the one you posted above.

When I inserted the code you provided nothing was returned. So, I tried <i>{section loop=$content_version.data_map.related_objects.content.additional_images}</i> and <i>{section loop=$content_version.data_map.related_objects.content.relation_list}</i> to no avail. I am sure that I am missing something obvious here...

Thanks again for your help!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Thursday 06 May 2004 6:38:39 am

Ah, the obvious thing is, and you will kick yourself:

related_objects is my attribute name, so:

$content_version.data_map.additional_images.content.relation_list

should do the trick.

paul

--
http://www.visionwt.com

Alex Jones

Thursday 06 May 2004 7:44:14 am

Actually I had a typo in my post above, the second example should have read <i>{section $content_version.data_map.additional_images.content.relation_list}</i> not <i>{section loop=$content_version.data_map.related_objects.content.relation_list}</i>. Sorry about that. I did double-check to make sure there weren't any typos, but everything looks to be right and yet nothing is output when I use <i>$content_version.data_map.additional_images.content.relation_list</i>. Here is the code that I am using. I cut it down a bit from what you provided by removing the class check

{default content_object=$node.object
         content_version=$node.contentobject_version_object}

{section loop=$content_version.data_map.additional_images.content.relation_list}
        {set relation_object=fetch(content,object,hash(object_id,$:item.contentobject_id,
                                                       object_version,$:item.contentobject_version))}
                 {content_view_gui view=full content_object=$relation_object}
				 
{/section}

{/default}

What am I missing?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Thursday 06 May 2004 7:57:46 am

Probably a couple of other things that i missed out at the start ;)

I forgot to create the related_object variable, which might be showing up on your debug output. Plus, check if you have a valid node object - I use this code within views, which always have a node.

{default content_object=$node.object
         content_version=$node.contentobject_version_object
         relation_object=0}

{section loop=$content_version.data_map.additional_images.content.relation_list}
        {set relation_object=fetch(content,object,hash(object_id,$:item.contentobject_id,
                                                       object_version,$:item.contentobject_version))}
                 {content_view_gui view=full content_object=$relation_object}
				 
{/section}

{/default}

paul

--
http://www.visionwt.com

Alex Jones

Thursday 06 May 2004 8:05:58 am

There we go, I'm much closer now! Thanks! The error was related to <i>relation_object</i> having not been set ahead of time. Not sure how I missed that. :P It's been a long day, and it's only 10AM here. :D

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Thursday 06 May 2004 8:35:33 am

Indeed, i forsee lots of problems during your day ;)

paul

Alex Jones

Thursday 06 May 2004 8:57:21 am

Thanks for the kind reassurance. ;)

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Clay Pereira

Thursday 06 May 2004 10:38:29 am

Could you please tell me how I would display the images.
when I use this code I see the image name and image version.

thank you
clay

Alex Jones

Thursday 06 May 2004 11:35:22 am

Clay, try changing the line <i>{content_view_gui view=full content_object=$relation_object}</i> to use a different <i>view</i>. For example, try using <i>{content_view_gui view=message content_object=$relation_object}</i> which should show you the picture alond with the rest of the information. I used that template as the basis for a new view.

You can do this by copying <i>design/standard/templates/content/view/message.tpl</i> into <i>design/YOURSITE/templates/content/view/YOUR_VIEW_TEMPLATE_NAME.tpl</i> where you can then modify to fit your needs. Then all you have to do is plug this line into your templates: <i>{content_view_gui view=your_view_template_name content_object=$relation_object}</i>.

My templates use: <i>{content_view_gui view=embed_related content_object=$relation_object}</i> as I named my view template <i>embed_related.tpl</i>. You will need to modify this template to meet your needs.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.