size
variable | size
returns number
Returns the size of a string or array.
The size of a string is the number of characters that the string includes. The size of an array is the number of items in the array.
{{ collection.title | size }}
{{ collection.products | size }}
{{ collection.title | size }}
{{ collection.products | size }}
{
"collection": {
"products": [],
"title": "Sale potions"
}
}
Output
12
4
Anchor to Dot notation
Dot notation
You can use the size
filter with dot notation when you need to use it inside a tag or object output.
{% if collection.products.size >= 10 %}
There are 10 or more products in this collection.
{% else %}
There are less than 10 products in this collection.
{% endif %}
{% if collection.products.size >= 10 %}
There are 10 or more products in this collection.
{% else %}
There are less than 10 products in this collection.
{% endif %}
{
"collection": {
"products": []
}
}
Output
There are less than 10 products in this collection.
Was this page helpful?