block-quote On this pagechevron-down
copy Copy chevron-down
Liquid chevron-right Filters group_by_exp Groups an array using a Liquid expression to determine the group key. Unlike group_by, which groups by a direct property value, group_by_exp lets you write arbitrary expressions to compute the grouping key.
Copy {% assign by_price_range = products | group_by_exp: "product" , "product.price > 100" %}
{% for group in by_price_range %}
{% log group . name | append : ": " | append : group . items . size | append : " products" %}
{% endfor %}
Copy {{ array | group_by_exp: item_name , expression }} Returns an array of group objects:
Group products by price range:
Copy {% assign by_range = products | group_by_exp: "p" , "p.price > 50" %}
{% for group in by_range %}
{% if group . name == true %}
{% log "Premium products: " | append : group . items . size %}
{% else %}
{% log "Budget products: " | append : group . items . size %}
{% endif %}
{% endfor %} Group by first letter of title:
Group orders by fulfillment state:
Group by computed value using filters:
Output:
Group line items by quantity tier:
The item_name parameter defines how you reference each item inside the expression
The expression can use any Liquid filters and operators
The expression result becomes the group name — it can be a string, number, boolean, etc.
Groups are returned in the order their keys are first encountered
For simple property-based grouping, group_by is more concise
See also: group_by, group_by_property, group_by_fast