shopify-list-contextcomponent
The list context component allows you to display multiple items in a repeating format. To use it, you need several key attributes:
type
: Defines what you're listing (such as 'product' or 'collection')query
: Specifies which data fields you want to displayfirst
: Sets the number of items to show in the listsort-key
(optional): Sets the key to sort the items by (e.g., 'TITLE', 'PRICE', etc.). Available sort keys depend on the context type and can be found in the Storefront API documentation (e.g. for product contexts, see ProductSortKeys).reverse-order
(optional): If present, reverses the sort order (descending instead of ascending)
Inside the list context, a template component defines how each item should appear. This template will automatically repeat for each item in your list. When you reference data within the template (using shopify-data or other components), it will automatically pull from the current item being displayed.
Sorting
- Use the
sort-key
attribute to specify the field to sort by. For example,will sort products alphabetically by title.
- Add the
reverse-order
boolean attribute to reverse the sort order (e.g., from ascending to descending).
The list context can be nested inside a context component or other list context components.
See the playground for examples.
Anchor to attributesAttributes
The number of items to return.
Defines where the list exists, either at the root or relative to a parent context. For example:
At the root, query a list of all products,
query="products"
Within a parent collection context, query the products on that collection,
query="collection.products"
The type of the context. This needs to match the GraphQL Storefront API type you are querying. For example, if you are querying a product, the type should be type="product"
.
The metaobject definition type for the context. Required when the context type is metaobject
.
Load the next page of items in the list.
Load the previous page of items in the list.
Reverse the order of the items in the list.
If present, reverses the sort order (descending instead of ascending)
Sets the key to sort the items by (e.g., 'TITLE', 'PRICE', etc.).
Available sort keys depend on the context type and can be found in the Storefront API documentation (e.g. for product contexts, see ProductSortKeys).
List context
HTML
Anchor to examplesExamples
Additional examples for using the
Anchor to example-sorting-with-sort-key-and-reverse-orderSorting with sort-key and reverse-order
Sorting products by title ascending and descending using sort-key and reverse-order.