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
A recommendation block in a Shopify theme is a Liquid section with a single setting: which Layers block to render. The Layers theme app extension does the rest — fetching products, tracking cart context, deduplicating across blocks on the same page, and submitting feedback when a shopper clicks a result. You only need to:- Read block metaobjects in Liquid to power the section setting (so merchandisers pick a block from a dropdown, not by typing an ID).
- Render a placeholder element with the selected block’s ULID handle.
- Call the Blocks API to fill it with products.
fetch. For the SDK version, see Rendering blocks with the SDK.
Prerequisites
- The Layers Shopify app installed. The app embed handles cart context, dedup, and click attribution automatically — your section only needs to fetch products.
- A storefront access token from
shop.metafields.layers.embed_settings. See Liquid integration.
The section
Createsections/layers-recommendations.liquid. The schema’s only setting is a select whose options are generated at render time from the configured block metaobjects.
Shopify schema is static JSON, so the block list can’t be generated inline. Use the snippet below to populate the dropdown at render time.
Generating block options in the theme editor
Render a small script in the theme that mirrors block metaobjects into the section’s setting list. Most themes do this with atheme.liquid snippet that updates the section schema via the Shopify Admin API on app install — but for storefronts that want a Liquid-only path, populate a <datalist> and switch the schema setting from select to text:
Fetching products
The section renders an empty placeholder with the block handle and the current page’s anchor. A small script fetches and hydrates each one.Anchors
The section reads the right anchor automatically based ontemplate:
| Template | anchor_id sent |
|---|---|
product | {{ product.id }} |
collection | {{ collection.handle }} |
| Anything else | omitted (cart-anchored and global blocks resolve without one) |
/cart.js or wiring up productsInCart.
What the app embed handles for you
Once the Layers theme app extension is installed and enabled, you do not need to:- Send
context.productsInCartfor cart-anchored blocks — the embed injects it. - Pass
excludeProductIdsbetween blocks — the embed dedupes by tracking product IDs rendered earlier on the page. - Wire up click attribution or feedback — the embed listens for clicks on rendered cards and submits feedback automatically.
- Provide identity (
deviceId,sessionId) — the storefront pixel manages it.
Empty blocks and fallbacks
The Blocks API runs the block’s fallback chain server-side. If the chain doesn’t produce results, the response is{ results: [] } — hide the section (as in the snippet above) rather than rendering an empty heading.
Troubleshooting
The section is empty in the theme editor. Make sure the merchandiser has selected a block in the section’s settings. The section hides itself whenblock_id is blank.
The block fetches but renders nothing. The block fell through its fallback chain — review configuration in the dashboard.
Cart recommendations look stale after /cart updates. The app embed re-runs cart-anchored blocks when the Shopify cart changes. If you’re not seeing updates, confirm the Layers theme app extension is enabled in Online Store → Themes → Customize → App embeds.
See also
- Rendering blocks with the SDK — SDK equivalent
- Blocks API — request and response reference
- Blocks and Fallback chains — dashboard configuration
- Liquid integration