Neil_Bradley
asked on
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 org/blog/s ort-array- modifier
However I am stuck with how to use it with with my foreach loop show here:
Cheers,
N
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;
}
I found this code here http://www.cmscanbesimple.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}
Pointers welcome..Cheers,
N
ASKER
Using this
The following was printed using@print_R
{foreach from=$items|sort_array item=entry}
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
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} .
$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} .
ASKER
Ok, here is a test page that shows the output http://www.beachcombercrui ses.co.nz/ test/
Code used is:
Code used is:
<pre>{$items|@print_r}
{foreach from=$items|sort_array item=entry}
<h4>{$entry->title|cms_escape}..</h4>
{/foreach}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help on this one. Much appreciated.
Cheers,
N
Cheers,
N
{$items|@print_r}
I hope you tried these method.
{foreach from=$items|sort_array item=entry}
<h4>{$entry->title|cms_esc
{/foreach}