Forums / Developer / Sorting multiple classes by custom attribute / Comment44725
Satoshi Kato
Saturday 23 September 2006 10:17:46 am
I solved this problem with ArraySortOperator by Marc Boon.http://ez.no/community/contribs/template_plugins/arraysortoperator
I use two arrays. One is a collection of fetched nodes. [(A) array]Another is an associative array for sorting. [(B) array]
The key of (B) array is index of (A) array.And value of (B) array is an attribute for sorting.
After sorting (B) array with asort or arsort operator,I can get sorted indexes of (A) array with 'foreach' structure.
For example, if multiple classes have 'pub_date' attribute...
{let list_items=array() sort_attributes=array()} {set $list_items=fetch_alias(children, hash(parent_node_id, $node.node_id))} {section var=child loop=$list_items} {set $sort_attributes = $sort_attributes|merge(hash($child.index, $child.data_map.pub_date.content.timestamp))} {/section} {set $sort_attributes = $sort_attributes|arsort()} {foreach $sort_attributes as $index => $item} {$list_items.$index.data_map.pub_date.content.timestamp|datetime('mydate')} {$list_items.$index.name}<br /> {/foreach} {/let}