group_by - Liquid Filter Reference - 0.10.11

Filter Name group_by
Group Collections
Version 0.10.11

Description

Groups an array of objects by a given property

Examples

When a string property is provided, it groups the collection by the provided property:
{% assign array = products | group_by: "type" %}
{% for group in array %}({{ group.name }}){% for item in group.items %}[{{ item.name }}]{% endfor %}{% endfor %}
(whitegoods)[Fridgetastic 3000][Coldinator 500](computers)[Geronimo 9000][Y2K Amaze]
When a variable property is provided, it groups the collection by the provided variable property:
{% assign array = products | group_by: grouping_field %}
{% for group in array %}({{ group.name }}){% for item in group.items %}[{{ item.name }}]{% endfor %}{% endfor %}
(whitegoods)[Fridgetastic 3000][Coldinator 500](computers)[Geronimo 9000][Y2K Amaze]

Back to Filter List

Back to Liquid Reference for 0.10.11

 

 
Back to Documentation