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
- Anchor to firstfirstnumberrequired
The number of items to return.
- Anchor to queryquerystringrequired
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"
- Anchor to typetypestringrequired
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"
.- Anchor to metaobject-definition-typemetaobject-definition-typestring
The metaobject definition type for the context. Required when the context type is
metaobject
.- Anchor to nextPagenextPage() => void
Load the next page of items in the list.
- Anchor to previousPagepreviousPage() => void
Load the previous page of items in the list.
- Anchor to reversereverse() => void
Reverse the order of the items in the list.
- Anchor to reverseOrderreverseOrderboolean
If present, reverses the sort order (descending instead of ascending)
- Anchor to sortKeysortKeystring
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).
ListContextAttributes
- first
The number of items to return.
number
- metaobject-definition-type
The metaobject definition type for the context. Required when the context type is `metaobject`.
string
- nextPage
Load the next page of items in the list.
() => void
- previousPage
Load the previous page of items in the list.
() => void
- query
Defines where the list exists, either at the root or relative to a parent context. For example: 1. At the root, query a list of all products, `query="products"` 2. Within a parent collection context, query the products on that collection, `query="collection.products"`
string
- reverse
Reverse the order of the items in the list.
() => void
- reverseOrder
If present, reverses the sort order (descending instead of ascending)
boolean
- sortKey
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](https://shopify.dev/docs/api/storefront/latest/enums/productsortkeys)).
string
- type
The type of the context. This needs to match the [GraphQL Storefront API](https://shopify.dev/docs/api/storefront) type you are querying. For example, if you are querying a product, the type should be `type="product"`.
string
interface ListContextAttributes extends BaseContextAttributes {
/**
* Defines where the list exists, either at the root or relative to a parent context. For example:
*
* 1. At the root, query a list of all products, `query="products"`
*
* 2. Within a parent collection context, query the products on that collection, `query="collection.products"`
**/
query: string;
/**
* The number of items to return.
**/
first: number;
/**
* 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](https://shopify.dev/docs/api/storefront/latest/enums/productsortkeys)).
**/
sortKey?: string;
/**
* If present, reverses the sort order (descending instead of ascending)
**/
reverseOrder?: boolean;
/**
* Load the next page of items in the list.
**/
nextPage?: () => void;
/**
* Load the previous page of items in the list.
**/
previousPage?: () => void;
/**
* Reverse the order of the items in the list.
**/
reverse?: () => void;
}
List context
HTML
examples
List context
description
List context example
HTML
<shopify-store store-domain="https://your-store.myshopify.com" > </shopify-store> <!-- The context is bound to the store --> <shopify-list-context type="product" query="products" first="10" > <!-- The template is repeated for each item in the array --> <template> <h2> <shopify-data query="product.title" ></shopify-data> </h2> </template> </shopify-list-context>
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.
Sorting with sort-key and reverse-order
HTML
examples
Sorting with sort-key and reverse-order
description
Sorting products by title ascending and descending using sort-key and reverse-order.
HTML
<shopify-store store-domain="https://your-store.myshopify.com"></shopify-store> <!-- Sort by title ascending --> <shopify-list-context type="product" query="products" first="3" sort-key="TITLE"> <template> <h2><shopify-data query="product.title"></shopify-data></h2> </template> </shopify-list-context> <!-- Sort by title descending --> <shopify-list-context type="product" query="products" first="3" sort-key="TITLE" reverse-order> <template> <h2><shopify-data query="product.title"></shopify-data></h2> </template> </shopify-list-context>