Forums / General / Trying to fetch related objects

Trying to fetch related objects

Author Message

Franck T.

Friday 07 April 2006 12:12:11 am

Hello all,
I'm trying to fetch all objects related to articles. So I've add this in my articles full view template:

 {let objects=fetch( 'content', 'related_objects', 
                       hash( 'object_id', $node.contentobject_id ) )}
   {section loop=$objects}
       <a href="{$objects.main_node.url_alias}">{$objects.name}</a>
   {/section}

I get this error:

Module start 'content' 
Error: eZModuleFunctionInfo::execute Apr 07 2006 09:05:43 
No such function 'related_objects' in module 'content' 

I'm surelly missing something ...

Kristof Coomans

Friday 07 April 2006 12:38:04 am

Which version of eZ publish are you using?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Franck T.

Friday 07 April 2006 12:48:05 am

I'm running the 3.6.0 on Win2K.

Franck T.

Friday 07 April 2006 1:07:19 am

Hum...
When I remove the simple quotes in <i>'content'</i> and <i>'related_objects'</i>, the system returns no error but it doesn't display the related objetcs.
What does it mean ??

Jo Henrik Endrerud

Friday 07 April 2006 1:26:56 am

according to kernel/content/function_definition.php it is no 'related_objects' functions for the fetch in the content module. You should rather do:

{let objects=$node.object.related_contentobject_array}

Jo Henrik Endrerud | System Developer @ Seeds Consulting | http://www.seeds.no

Franck T.

Friday 07 April 2006 1:50:23 am

Thanks Jo but where did you find this?
Is the doc out-of-date? http://ez.no/doc_hidden/ez_publish/technical_manual/3_6/reference/modules/content/fetch_functions/related_objects

...
{* For related objects: *}
 
{let objects=$node.object.related_contentobject_array}
   {section loop=$objects}
       <a href="{$objects.main_node.url_alias}">{$objects.name}</a>
   {/section}

...

No debug error but still no objects displayed !!

Kristof Coomans

Friday 07 April 2006 2:02:44 am

The related_objects and related_objects_count fetch functions were introduced in version 3.6.3 ( http://pubsvn.ez.no/nextgen/stable/3.6/doc/changelogs/3.6/CHANGELOG-3.6.2-to-3.6.3 ).

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Jo Henrik Endrerud

Friday 07 April 2006 2:05:27 am

Hmm... I checked in the code for 3.5. Looks like the fetch function you use was created for 3.6, so it should work for you the way you tried.
The problem might be your loop. Can you check the source of the output and see if the links actually are there, but without any link text?
If so, the problem is that you have just forgot to add a var-name for your loop. The loop should be something like this:

{section loop=$objects var=myloop}
     <a href={$myloop.item.main_node.url_alias|ezurl}>{$myloop.item.name}</a>
{/section}

The ezurl i added is not related to this problem, but it's best practice to use, so I added it for you.

Jo Henrik Endrerud | System Developer @ Seeds Consulting | http://www.seeds.no

Franck T.

Friday 07 April 2006 3:14:49 am

OK Jo, you're right: the var-name was missing in my loop. Now it works fine.
Amazed ...
Thanks a lot. Really.

A last question just to be complete: in my template, is there a way to inform users with something like "No additional info" when the given artice has no related object ?