Documentation Index
Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This is the SDK equivalent of Rendering facets in Liquid. The pattern is identical — read facet metaobjects in Liquid, then resolve runtime facet values, counts, and ranges from Layers — but the SDK’sclient.collection() controller handles the HTTP request, request deduplication, caching, abort signals, and filter-group transformation for you, and exposes results as a reactive signal you can subscribe to.
Use this version when you’ve already installed @commerce-blocks/sdk in your theme. If you’re scripting against the storefront API directly with fetch, see the vanilla Liquid + Fetch guide instead.
Prerequisites
- The Layers Shopify app installed and synced.
- Facets configured in the Layers dashboard with Enable as Storefront Facet turned on.
- The SDK installed and a client created in your theme. See SDK installation.
The pattern
Read facet metaobjects in Liquid
Render the sidebar shell from metaobjects exactly like the Fetch version. Each
<section> carries the facet code so the SDK results can be matched to the right group.Create a collection controller
client.collection() returns a reactive controller. Its state signal updates every time execute() runs, and the SDK deduplicates identical in-flight requests and caches results in localStorage.retrieveFacetCount / includeFacetRanges flag to set. data.facets is the value-count map, and numeric ranges are exposed on top-level fields like data.priceRange (when variants.price is in your facets config).Render values, counts, and ranges
The render code looks at the same
data-facet-code attributes as the Fetch version.Refreshing counts as filters are applied
Callexecute({ filters }) whenever the active selection changes. The SDK reuses the same controller, dedupes against in-flight requests, and updates the state signal — subscribers re-render automatically.
color → options.color), the SDK resolves them automatically — you can keep the URL- and UI-friendly keys in your form names.
Why the SDK over Fetch
| Concern | Fetch version | SDK version |
|---|---|---|
| Request body shape | Hand-rolled filter_group | Plain filters object, optionally with aliases |
| Counts and ranges | Opt in via retrieveFacetCount / includeFacetRanges | Always returned |
| Caching | DIY | Built-in cache with cacheLifetime and localStorage persistence |
| Deduplication | DIY | Built-in RequestCoordinator |
| Abort handling | DIY AbortController | Built-in per-controller |
| Reactivity | DIY | Signal-based subscribe() |
Troubleshooting
data.facets is empty. Confirm the facets you expect are listed in the facets array passed to createClient. The SDK only requests facet codes it knows about.
Counts don’t change when filters are applied. Make sure you’re passing the active filters to execute({ filters }) — the SDK doesn’t watch the DOM. Subscribe to the controller state and re-render on every emit.
data.priceRange is undefined. priceRange requires { name: 'Price', code: 'variants.price' } in your facets config. See Responses and errors.
See also
- Rendering facets in Liquid (Fetch) — the no-dependency equivalent of this guide
- SDK installation — config reference including
sorts,facets, andfilterAliases - Client methods →
client.collection()— full controller API - Filtering — filter DSL reference
- Liquid integration — reading metaobjects in Liquid