This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Setup & design » How to sort arrays of ez content...
expandshrink

How to sort arrays of ez content objects?

How to sort arrays of ez content objects?

Tuesday 16 September 2008 5:02:54 pm - 7 replies

Hi,
I want to sort array of ez content objects by the object name. The problem is that I'm not getting them with a fetch which would sort them properly because I need to create custom array that contain some ez content object.

Does anyone know a good solution?

Wednesday 17 September 2008 1:16:17 pm

I have the same question.
+1

Wednesday 17 September 2008 1:29:18 pm

You can create a new hash array and sort it afterwards using an extension:

http://ez.no/developer/contribs/template_plugins/arraysortoperator

...untested...

{def $new_array = array()} 
{foreach $children as $child}
		{set $new_array=$new_array|append(hash('name',$child.name,'ezobject',$child))}
{/foreach}

{set $new_array=$new_array|sort}

Modified on Wednesday 17 September 2008 4:46:17 pm by Andreas Adelsberger

Wednesday 17 September 2008 4:44:15 pm

Thanks Andreas for your solution it's great and work fine for my project, only one thing I have declared variable as an array:

{def $new_array = array()}

Wednesday 17 September 2008 4:46:46 pm

You are welcome. I fixed it in the code above.

Thursday 24 November 2011 10:46:10 am

Thank you Andreas and Daniele.

This is a good solution to my problem too!

Thursday 03 May 2012 2:04:33 pm

Thx Andreas, your solution is good.

Thursday 16 August 2012 11:29:07 am

Hi,

I have the same problem I need to sort an array of ez objects.

Could you give a detail example of the use of this extension, i just tried this but it doesn't work :

 {def $new_array = array(2,8,4,33,4,7)} 
{set $new_array=$new_array|sort()}
{$new_array|attribute(show)}

Nothing is printed.

Thanks,

greetings

ben

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from