Sort grandchildren

Author Message

Softriva .com

Tuesday 02 January 2007 11:46:54 pm

Hello,

I have a listing as

M2 (node #301)
--S1 (node #401)
--S3 (node #402)
--S2 (node #403)

M1(node #302)
--S1 (node #401)
--S3 (node #402)
--S2 (node #403)

I do fetching as

{def $cM=fetch(content,list, hash('parent_node_id', 59,'sort_by',array( 'priority', true() )))}

When I list them they appear as

M1 (node #302)
--S1 (node #401)
--S3 (node #402)
--S2 (node #403)

M2(node #301)
--S1 (node #401)
--S3 (node #402)
--S2 (node #403)

Note that only M1 and M2 are sorted based on priority but not S1, S2 and S3.

I use the following code to list them

{foreach $cMs as $cM}
	{$cM.name|wash}
		{foreach $cM.children as $child}
			<a href={$child.url_alias|ezurl()}>{$child.name|wash}</a>
		{/foreach}
{/foreach}

How can I sort S1, S2 and S3?

André R.

Wednesday 03 January 2007 3:35:34 am

$some_node.children is not sorted, and as you will see from the debug output the children is fetched when you call $some_node.children (the ezcontentobjecttreenode object have several dynamicly fetched methods).

So instead I suggest you do something like this:

{def $cMs=fetch(content,list, hash('parent_node_id', 59,'sort_by',array( 'priority', true() )))
      $subM=false()}
{foreach $cMs as $cM}
        {$cM.name|wash}
        {if $cM.is_container}
            {set $subM=fetch(content,list, hash('parent_node_id', $cM.node_id,'sort_by',array( 'priority', true() )))}
                {foreach $subM as $child}
                        <a href={$child.url_alias|ezurl()}>{$child.name|wash}</a>
                {/foreach}
        {/if}
{/foreach}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Softriva .com

Thursday 04 January 2007 2:39:36 am

Thank you, worked perfect.

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