1

I have entries that I would like to sort by 2 fields. First I would like to sort (or group) all of the entries in alphabetical order by a category field (brand), and then within each grouped brand I would like to sort the entries by a number field ascending (size).

I can perform both sorts individually with the syntax below, but I’m having difficulty combining them for a multisort-like function.

 entries|supersort('sortAs', '{ brand.first.title }')
 entries|supersort('sortAs', '{ size }', SORT_NUMERIC)

1 Answer 1

2

Try to group the entries sorted by size using the group filter:

{% set entriesSorted = entries|supersort('sortAs', '{ size }', SORT_NUMERIC) %}
{% set entriesByBrand = entriesSorted|group('brand.first.title') %}
{% set entriesByBrand = entriesByBrand|supersort('ksort') %}

{% for brand, entriesInBrand in entriesByBrand %}
    {% for entry in entriesInBrand %}
        <li>{{ entry.title }}</li>
    {% endfor %}
{% endfor %}
2
  • Thanks that grouped my entries by brand and ordered them by size. Is there a way to have the grouped brands display alphabetically? Commented Dec 2, 2015 at 14:16
  • Try to add another Supersort filter using 'ksort' method @triplethreat23!
    – carlcs
    Commented Dec 2, 2015 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.