smarty sort by modif

I all,
working with CMSMS I am trying to output items in a foreach loop (news items) to that they show by title alphabetically.
I have added a file to the plugins section with the following code
function smarty_modifier_sort_array($array)
{
    asort($array);
    return $array;   
}

Open in new window

I found this code here http://www.cmscanbesimple.org/blog/sort-array-modifier
However I am stuck with how to use it with with my foreach loop show here:
// show by title alphabetically
{foreach from=$items item=entry} 
<h4>{$entry->title|cms_escape}..</h4>
{/foreach}

Open in new window

Pointers welcome..
Cheers,
N
LVL 5
Neil_BradleyWeb UX/UI DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

InsoftserviceCommented:
Please print array so that it would be easy to check the issue of sorting
{$items|@print_r}
I hope you  tried these method.
{foreach from=$items|sort_array item=entry}
<h4>{$entry->title|cms_escape}..</h4>
{/foreach}
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Using this
{foreach from=$items|sort_array item=entry} 

Open in new window

almost worked. It did re order my list but not quite alphabetically.
The following was printed using@print_R  
Array ( [0] => stdClass Object ( [author_id] => 3 [author] => editor [authorname] => [id] => 38 [title] => Europcar New Zealand [content] => Europcar New Zealand prides itself on its excellent service, competitive rates and wide selection of reliable fleet vehicles. With over 20 locations across New Zealand including Picton, Europcar truly is a national auto hire company. Europcar's large diverse fleet in New Zealand has a model to suit your vehicle hire requirements. [summary] => [postdate] => 2015-06-19 15:15:16 [startdate] => [enddate] => [create_date] => 2015-06-19 15:17:06 [modified_date] => 2015-06-19 17:43:48 [category] => Transport [fields] => Array ( [photo] => news_field Object ( [_data:news_field:private] => Array ( [id] => 4 [name] => photo [type] => textarea [max_length] => 255 [item_order] => 1 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => ) [_displayvalue:news_field:private] => ) [website] => news_field Object ( [_data:news_field:private] => Array ( [id] => 5 [name] => website [type] => textbox [max_length] => 255 [item_order] => 2 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => https://www.europcar.co.nz/beachcomber-cruises ) [_displayvalue:news_field:private] => ) [tel] => news_field Object ( [_data:news_field:private] => Array ( [id] => 6 [name] => tel [type] => textbox [max_length] => 255 [item_order] => 3 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => 0800 248 963 ) [_displayvalue:news_field:private] => ) [latitude] => news_field Object ( [_data:news_field:private] => Array ( [id] => 7 [name] => latitude [type] => textbox [max_length] => 255 [item_order] => 4 [public] => 1 [extra] => a:1:{s:7:"options";N;} ) [_displayvalue:news_field:private] => ) [longtitude] => news_field Object ( [_data:news_field:private] => Array ( [id] => 8 [name] => longtitude [type] => textbox [max_length] => 255 [item_order] => 5 [public] => 1 [extra] => a:1:{s:7:"options";N;} ) [_displayvalue:news_field:private] => ) [book] => news_field Object ( [_data:news_field:private] => Array ( [id] => 9 [name] => book [type] => textbox [max_length] => 255 [item_order] => 6 [public] => 1 [extra] => a:1:{s:7:"options";N;} ) [_displayvalue:news_field:private] => ) ) [fieldsbyname] => Array ( [photo] => news_field Object ( [_data:news_field:private] => Array ( [id] => 4 [name] => photo [type] => textarea [max_length] => 255 [item_order] => 1 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => ) [_displayvalue:news_field:private] => ) [website] => news_field Object ( [_data:news_field:private] => Array ( [id] => 5 [name] => website [type] => textbox [max_length] => 255 [item_order] => 2 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => https://www.europcar.co.nz/beachcomber-cruises ) [_displayvalue:news_field:private] => ) [tel] => news_field Object ( [_data:news_field:private] => Array ( [id] => 6 [name] => tel [type] => textbox [max_length] => 255 [item_order] => 3 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => 0800 248 963 ) [_displayvalue:news_field:private] => ) [latitude] => news_field Object ( [_data:news_field:private] => Array ( [id] => 7 [name] => latitude [type] => textbox [max_length] => 255 [item_order] => 4 [public] => 1 [extra] => a:1:{s:7:"options";N;} ) [_displayvalue:news_field:private] => ) [longtitude] => news_field Object ( [_data:news_field:private] => Array ( [id] => 8 [name] => longtitude [type] => textbox [max_length] => 255 [item_order] => 5 [public] => 1 [extra] => a:1:{s:7:"options";N;} ) [_displayvalue:news_field:private] => ) [book] => news_field Object ( [_data:news_field:private] => Array ( [id] => 9 [name] => book [type] => textbox [max_length] => 255 [item_order] => 6 [public] => 1 [extra] => a:1:{s:7:"options";N;} ) [_displayvalue:news_field:private] => ) ) [file_location] => http://www.beachcombercruises.co.nz/uploads/news/id38 [link] => http://www.beachcombercruises.co.nz/news/38/122/Europcar-New-Zealand/ [titlelink] => Europcar New Zealand [morelink] => More [moreurl] => http://www.beachcombercruises.co.nz/news/38/122/Europcar-New-Zealand/ ) ) 1

Open in new window

InsoftserviceCommented:
while sending data via php to html cast it to array
$items = (array)$items;
So that you would be having proper array in foreach.
in your tpl try print the o/p
<pre>{$items|@print_r} .
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Ok, here is a test page that shows the output http://www.beachcombercruises.co.nz/test/

Code used is:
<pre>{$items|@print_r}
{foreach from=$items|sort_array item=entry} 
<h4>{$entry->title|cms_escape}..</h4>
{/foreach}

Open in new window

InsoftserviceCommented:
its multidimensional array and can not be sorted using these method.
Either use below function and do it in php or create  Smarty modifier as mentioned in your link with the below function

function aasort (&$array, $key) {
    $sorter=array();
    $ret=array();
    reset($array);
    foreach ($array as $ii => $va) {
        $sorter[$ii]=$va[$key];
    }
    asort($sorter);
    foreach ($sorter as $ii => $va) {
        $ret[$ii]=$array[$ii];
    }
    $array=$ret;
}
$items = (array)$items;
aasort($items,"title");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Thanks for your help on this one. Much appreciated.
Cheers,
N
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.