GDPR privacy disclaimer
This form will send me your email address and your IP address.
If you don't want that, don't use this form!
Sort array modifier
Previous article Next articleSorting the output of an array with this simple Smarty modifier. Sometimes has a problem, a very simple solution...
I was grateful inspired by http://stackoverflow.com when making this.
Create a file named "modifier.sort_array.php" and add it to the CMS Made Simple /plugins folder
<?php
/**
* Smarty sort_array modifier plugin
*
* Type: modifier
* Name: sort_array
* Purpose: alphabetize an array
*
* https://www.cmscanbesimple.org/blog/sort-array-modifier
*/
function smarty_modifier_sort_array($array)
{
asort($array);
return $array;
}
?>
/**
* Smarty sort_array modifier plugin
*
* Type: modifier
* Name: sort_array
* Purpose: alphabetize an array
*
* https://www.cmscanbesimple.org/blog/sort-array-modifier
*/
function smarty_modifier_sort_array($array)
{
asort($array);
return $array;
}
?>
How to use
You can alphabetize the output in your template like:
{foreach from=$item|sort_array item='bar'}
{$bar}
{/foreach}
{$bar}
{/foreach}
{foreach $nodes|sort_array as $node}
+++ menu template +++
{/foreach}
+++ menu template +++
{/foreach}
Working example
- Recipe tag list
- But also the tag list below...
Comment Form
ReviewManager
ReviewManager
2 Comments
08-04-2017
informative blog.. i got more useful information from this blog..
best php training
08-04-2017
useful blog to read... thanks a lot for sharing this blog to us