has
array | has: string, string
returns boolean
Tests if any item in an array has a specific property value.
This requires you to provide both the property name and the associated value.
{% assign has_potent_potions = collection.products | has: 'vendor', "Polina's Potent Potions" %}
{{ has_potent_potions }}
{% assign has_potent_potions = collection.products | has: 'vendor', "Polina's Potent Potions" %}
{{ has_potent_potions }}
{
"collection": {
"products": [
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Clover's Apothecary"
}
]
}
}
Output
true
Anchor to Returns `false` when no items match the specified property value.
Returns false
when no items match the specified property value.
false
when no items match the specified property value.{% assign has_potent_potions = collection.products | has: 'vendor', "Polina's Potions" %}
{{ has_potent_potions }}
{% assign has_potent_potions = collection.products | has: 'vendor', "Polina's Potions" %}
{{ has_potent_potions }}
{
"collection": {
"products": [
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Clover's Apothecary"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Polina's Potent Potions"
},
{
"vendor": "Ted's Apothecary Supply"
},
{
"vendor": "Clover's Apothecary"
}
]
}
}
Output
false
Was this page helpful?