Collections
Group and organise collections of objects in Easol themes.
Collection filters help organise arrays of objects before rendering them.
They're particularly useful when displaying products, variants, extras, events, or search results that should be grouped under headings.
Group by a property
Use group_by to group objects that share the same value for a property.
For example, you might group events by their start time.
{% assign grouped_events = events | group_by: "time" %}
{% for group in grouped_events %}
<article>
<h2>{{ group.name }}</h2>
{% for event in group.items %}
<p>{{ event.name }}</p>
{% endfor %}
</article>
{% endfor %}This renders:
<article>
<h2>10:00</h2>
<p>Surf</p>
<p>Oneness</p>
</article>
<article>
<h2>12:30</h2>
<p>Yoga</p>
</article>Each group contains:
group.name— the grouped value.group.items— the items belonging to that group.
Group by an expression
Sometimes you want to group by a transformed value rather than a raw property.
Use group_by_expression to evaluate a Liquid expression for each object before grouping.
A common example is grouping events by date while ignoring the time.
{% assign grouped_events = events | group_by_expression: "event", "event.start_at | date: '%Y-%m-%d'" %}
{% for group in grouped_events %}
<article>
<h2>{{ group.name }}</h2>
{% for event in group.items %}
<p>{{ event.name }}</p>
{% endfor %}
</article>
{% endfor %}This renders:
<article>
<h2>2000-01-01</h2>
<p>Yoga</p>
</article>
<article>
<h2>2000-01-02</h2>
<p>Surf</p>
<p>Oneness</p>
</article>Because the grouping key is generated from a Liquid expression, you can group by formatted dates, calculated values, or combinations of object properties.
Common use cases
Collection filters are commonly used to group:
- Variants by segment.
- Extras by segment.
- Events by date or time.
- Search results by category.
- Products by location.
Choosing the right filter
| Filter | Use when |
|---|---|
group_by | Group by an existing property, such as segment_name or category. |
group_by_expression | Group by a calculated or formatted value, such as a formatted date. |