Implements uSort into Twig.
To install Twig uSort, follow these steps:
- Download & unzip the file and place the
twigusort
directory into yourcraft/plugins
directory - -OR- do a
git clone https://github.com/roberttolton/twigusort.git
directly into yourcraft/plugins
folder. You can then update it withgit pull
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
twigusort
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
Twig uSort works on Craft 2.4.x and Craft 2.5.x.
Example usage:
{% set entries = craft.entries.section('testEntries').find() | twigUsort( 'testField', '["Apple","Orange","Banana"]' ) %}
{% for entry in entries %}
{{ entry.title }}<br/>
{{ entry.testField }}<br/>
<hr/>
{% endfor %}
The first parameter is a field handle, the second is a JSON encoded array of ALL the correct values in their desired order.
Some things to do, and ideas for potential features:
- Don't know yet!
- Initial release
Brought to you by Robert Tolton