Is there a way to sort related_contentobject_array on node names?

Author Message

Conor Murray

Wednesday 10 September 2003 9:29:40 am

I'm drawing a blank with this one... I want to use related content to generate links in alphabetic sequence, but because these values are contained within an array in a single node, I can't see any way of using fetch to sort them for me.

Here's the loop I'm using to output the links, without any formatting elements:

{let Linkholder=fetch(content,node,hash(node_id,496))}
{section loop=$Linkholder.object.related_contentobject_array}
{content_view_gui view=text_linked content_object=$:item}
{/section}
{/let}

This works fine, except the array appears to be sorted by node obect order, where I really want to sort in alphabetical sequence on the names of the related objects.

Has anyone got any suggestions please?

Language is a virus - William S Burroughs

Gunnstein Lye

Thursday 11 September 2003 5:07:17 am

This is not supported directly. You have a few options:

1. Create a template operator that takes $Linkholder.object.related_contentobject_array as an argument and returns a sorted list.

or
2. Modify the relatedContentObjectArray() function in kernel/classes/ezcontentobject.php so that it sorts the result by name. ("ORDER BY ezcontentobject.name" at the end of the SQL query should do the trick, I think.)

or
3. Create a template operator that takes an object as an argument and returns a sorted list of related objects. It's about the same as #2, but cleaner.

Conor Murray

Thursday 11 September 2003 5:39:01 am

Thanks Gunnstein,

I went with the quick, dirty fix (suggestion 2), as I doubt I will ever want to display this data in anything other than alphabetical sequence. The modification you suggested worked perfectly :-)

I'm currently trying to stick to using the default template operators as much as possible, but I can see that for some sites it will be necessary to create new operators. When I find the time I will write a few template operators of my own, but that won't be tomorrow!

Thanks again for your very useful and accurate reply :-)

Language is a virus - William S Burroughs

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