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 blocks in Liquid. The shape of the section is the same — one Liquid section, one merchandiser-facing block-picker setting — butclient.blocks() does the HTTP call, dedupes against in-flight requests, caches results in localStorage, and exposes the products on a reactive signal.
You do not need to handle cart context, click feedback, or cross-block product deduplication. The Layers theme app extension handles those for every Blocks request on the storefront.
Use this version when you’ve already installed @commerce-blocks/sdk in your theme. For a no-dependencies version, see the Liquid + Fetch guide.
Prerequisites
- The Layers Shopify app installed and the theme app extension enabled in Online Store → Themes → Customize → App embeds.
- The SDK installed and a client created in your theme — see SDK installation and the setup snippet for generating
sorts/facetsfrom metaobjects.
The section
sections/layers-recommendations.liquid is the same Liquid scaffold as the Fetch version — a section with a block-picker setting and a single placeholder element carrying the selected block handle.
select options are populated from block metaobjects — see the Fetch guide for the pattern that mirrors metaobjects into the dropdown so merchandisers pick by name instead of pasting a ULID.
Hydrating the section
For each rendered section, create aclient.blocks() controller with the selected handle and the page’s anchor. Subscribe to the state signal and render on data changes.
What the app embed handles for you
When the Layers theme app extension is enabled, the storefront-side embed augments every Blocks request — including the SDK’s — so you don’t have to:- Cart context — current cart line items are sent automatically; cart-anchored blocks work without you reading
/cart.js. - Product deduplication — products rendered earlier on the page are excluded from later blocks automatically.
- Click attribution and feedback — the embed listens for clicks on rendered cards and submits feedback to keep ranking models fresh.
- Identity — the storefront pixel manages
deviceIdandsessionId.
Anchors
client.blocks({ blockId, anchor }) resolves the right value based on template:
| Template | anchor |
|---|---|
product | {{ product.id }} |
collection | {{ collection.handle }} |
| Anything else | omitted (cart-anchored and global blocks resolve without one) |
Why the SDK over Fetch
| Concern | Fetch version | SDK version |
|---|---|---|
| Driving the request | fetch to /blocks/{id}/products | blocks.execute() |
| Re-renders | DIY DOM updates | Signal subscriber |
| Caching across nav | DIY | Restored from localStorage |
| Multiple blocks per page | Manual orchestration | Independent controllers, SDK dedupes identical requests |
Troubleshooting
The section renders but the grid stays empty. The block fell through its fallback chain. Review fallback configuration in the dashboard. Block-picker dropdown is empty. Confirm block metaobjects are visible under Content → Metaobjects in Shopify admin, and that you’ve populated the section setting from those metaobjects (see the Fetch guide for the pattern). Cart-anchored blocks don’t refresh on cart changes. The theme app extension re-runs cart-anchored blocks. Confirm it’s enabled under Online Store → Themes → Customize → App embeds.See also
- Rendering blocks in Liquid (Fetch) — the no-dependency equivalent
- Client methods →
client.blocks() - Blocks API
- Blocks and Fallback chains