only - Liquid Filter Reference - 1.1.0

Filter Name only
Group Arrays
Version 1.1.0

Description

Returns all items in the array where the supplied property equals one of the supplied values

Examples

When both a property and value are supplied, it returns items from the array that match the supplied property and value:
{% new List products = '[{"name":"Fridgetastic 3000","type":"whitegoods","new":false},{"name":"Coldinator 500","type":"whitegoods","new":false},{"name":"Geronimo 9000","type":"computers","new":false},{"name":"Y2K Amaze","type":"computers","new":true},{"name":"Elephant","type":"animals","new":false}]' %}

{{ products | only: "type", "whitegoods" | pluck: "name" | join: ", " }}
Fridgetastic 3000, Coldinator 500
When multiple values are supplied, it returns items from the array where the supplied property equals one of the supplied values:
{% new List products = '[{"name":"Fridgetastic 3000","type":"whitegoods","new":false},{"name":"Coldinator 500","type":"whitegoods","new":false},{"name":"Geronimo 9000","type":"computers","new":false},{"name":"Y2K Amaze","type":"computers","new":true},{"name":"Elephant","type":"animals","new":false}]' %}

{{ products | only: "type", "whitegoods", "computers" | pluck: "name" | join: ", " }}
Fridgetastic 3000, Coldinator 500, Geronimo 9000, Y2K Amaze
When only a property is supplied, it returns items from the array where the supplied property is a truthy value:
{% new List products = '[{"name":"Fridgetastic 3000","type":"whitegoods","new":false},{"name":"Coldinator 500","type":"whitegoods","new":false},{"name":"Geronimo 9000","type":"computers","new":false},{"name":"Y2K Amaze","type":"computers","new":true},{"name":"Elephant","type":"animals","new":false}]' %}

{{ products | only: "new" | pluck: "name" | join: ", " }}
Y2K Amaze

Back to Filter List

Back to Liquid Reference for 1.1.0

 

 
Back to Documentation