This plugin allows you to specify the sorting-method for Twigs sort-filter in Craft-CMS.
##Methods:
##Examples:
Basics:
|sort(method, sort-flag)Sort entries with natsort:
{% for entry in craft.entries.section('news').find()|sort('natsort') %}....{% endfor %}Sort-flags:
If the php-function supports sort-flags, you can pass them in a second parameter.
{% for entry in craft.entries.section('news').find()|sort('sort', 'SORT_NUMERIC') %}....{% endfor %}##Install:
- Move the
twigbettersortdirectory into thecraft/plugins/directory. - Go to Settings -> Plugins and enable 'Twig Better Sort Filter'.
##Note:
If another plugin tries to override the sort-filter, only the latest override will be applied.
To avoid this, open 'TwigBetterSortTwigExtension.php' and replace:
return array('sort' => new \Twig_Filter_Method($this, 'twig_sort'));with
return array('better_sort' => new \Twig_Filter_Method($this, 'twig_sort'));This will leave the sort-filter alone and create a 'better_sort'-filter instead:
|better_sort(method, sort-flag)