Skip to content
Log in

List - Liquid Variable

On this page

Description

A List represents a simple collection of items, like an array. You can access items directly by index, look them up by key, or loop through them. List collections load all records at once.

Property Value
Type List
String Representation List[ContentType]
Index Access Yes (list[0])
Key Lookup Yes (list["key"])

Attributes

Attribute Type Description
any? Boolean Returns true if the List contains at least one item
first Object Returns the first item in the List
last Object Returns the last item in the List
size Number Returns the number of items in the List
[] Object Access items by integer index (e.g. list[0]) or by key (e.g. list["slug"])
each Iterator Iterate over all items using a {% for %} loop

Examples

Looping through a List

```liquid {% for product in collection.products %}

{{ product.name }}

{% endfor %} ```

Accessing by index

liquid {{ collection.products[0].name }} {{ collection.products.first.name }} {{ collection.products.last.name }}

Accessing by key

liquid {{ pages["about-us"].name }}

Checking if the list has items

liquid {% if collection.products.any? %} {{ collection.products.size }} products found {% endif %}

Was this article helpful?

Was this article helpful?