Skip to content

victor-sm/Craft-TwigBetterSort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Craft-TwigBetterSort

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:

  1. Move the twigbettersort directory into the craft/plugins/ directory.
  2. 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)

About

Extended Twig Sort-Filter for Craft CMS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages