Liquid Tutorial

Array Filters

Source: Coding with Robby

Working with Lists

Collections, cart items, product images, and linklists are arrays. Array filters let you count, sort, filter, and transform them without JavaScript.

Filter and sort products
{{ collection.products | size }}
{{ collection.products | first | map: 'title' }}
{{ collection.products | where: 'available', true | size }}
{{ collection.products | sort: 'price' | reverse | first | map: 'title' }}
  • size — count items
  • first / last — get boundary elements
  • where: 'property', value — filter objects by property
  • sort: 'property' — alphabetical or numeric sort
  • map: 'property' — extract one property from each item into an array
  • uniq — remove duplicates
  • join: ', ' — combine into a string
Note: where only supports exact equality. For tag filtering, loop with {% if product.tags contains 'tag' %} instead.