Block rules
Rules let you change block behavior based on the anchor product or request context. Layers evaluates rules on every block request, in order, and applies every matching rule. It stops evaluating only after a matching action hides the block. Rules never change which block is served. Layers always selects the highest-priority block for the anchor, then matching rules adjust that block’s effective configuration. A block whose rule conditions don’t match keeps its base configuration.Rule shape
Each rule contains one set of conditions and one action. Theconditions.combinator joins the condition rules with and or or. Each condition names a field, an operator, and a value. The action is an object with a type and optional action-specific fields. Its type is one of apply_filter, promote, demote, hide_block, change_strategy, or override_safeguards.
apply_filter, promote, and demote accept a filter_group. change_strategy accepts strategy_type and strategy_key. override_safeguards accepts safeguards. hide_block has no additional fields. The filter_group uses the storefront filter expression vocabulary. See the filter group reference for its shape. The conditions object uses the field vocabulary below.
Field vocabulary
The supported filter operators areeq, neq, in, notIn, gt, gte, lt, lte, contains, doesNotContain, beginsWith, endsWith, doesNotBeginWith, doesNotEndWith, null, notNull, between, notBetween, inLast, after, before, geoRadius, geoPolygon, and geoBoundingBox. In block conditions, the editor also supports the symbolic aliases = and != for equality and inequality, plus in and notIn for shopping channel values.
Custom context parameters your storefront sends in
context.custom also join the vocabulary as context.custom.<path> fields once Layers discovers them in traffic. If a discovered parameter shares a name with a shipped field listed above, the shipped field wins. See Custom context fields for discovery requirements.
For list fields such as anchor_product.tags and anchor_product.collections, the = operator matches when the list contains the value. anchor_product.tags = sale matches any anchor product tagged sale. anchor_product.collections contains both collection IDs and collection handles, so a condition can reference either.
Examples
Apply a vendor filter when the anchor product comes from Acme:on_sale catalog filter when the anchor product is a Catalog product:
sale:
Rule actions
Apply Filter
Apply Filter
Add additional filtering to the block’s product results.Use cases:
- Show only products from the same vendor as the anchor product
- Filter by price range based on anchor product price
- Show only products with specific tags
- Apply geographic filtering (e.g., show winter products to cold climates)
Promote / Demote matching products
Promote / Demote matching products
Re-rank the block’s results without changing which products are returned. Each matching
promote or demote rule adds a ranking tier defined by its filter_group. Products matching a promote tier rank first. Products matching a demote tier rank last. Everything else keeps its normal order in between.Tiers are ranking-only. They never filter products out, and pagination stays stable across pages. Diversity caps, spacing, and sequential sorting still apply within each tier.Use cases:- Rank same-vendor products first on a “You may also like” block
- Push clearance items to the end of a recommendation rail
- Surface on-sale products first during a promotion
Hide Block
Hide Block
Hide the block entirely when conditions are met. The fallback chain will be used instead.Use cases:
- Hide “Frequently Bought Together” if anchor product is out of stock
- Hide blocks for specific customer segments
- Hide blocks for app requests
- Hide blocks for specific geographic regions
Change Strategy
Change Strategy
Switch to a different strategy when conditions are met. The new strategy must return the same result type as the block: a rule can’t switch a product block to the related content strategy, or a content block to a product strategy.Use cases:
- Use “Similar Products” for app requests instead of “Frequently Bought Together”
- Switch to different interaction strategies based on customer segment
- Use different strategies for different product types
Override Safeguards
Override Safeguards
Modify the block’s safeguards (min/max products, hide out of stock) based on conditions.Use cases:
- Show more products for VIP customers
- Adjust minimum products for returning customers
- Enable or disable out-of-stock filtering for specific customer segments
Multiple rules
You can configure multiple rules for a single block. Layers evaluates them in order and applies each matching action until a hide action stops evaluation. Put broad conditions after more specific conditions.Safeguards
Safeguards ensure blocks display appropriately and provide a good customer experience.Product safeguards don’t apply to content blocks. A block using the related content strategy can’t configure hide out of stock or the diversity cap.
Hide out of stock
Automatically filter out products that are not available for purchase. Behavior:- Products with no available variants are excluded from results
- If your store’s inventory location scope is narrowed, blocks apply the same location rules as search. A variant counts as available if it meets any of these conditions:
- It has stock at a location in the scope
- Shopify is set to keep selling it when out of stock
- Its inventory is untracked
- A product is hidden only when none of its variants meet any of these conditions
- Applies after strategy execution but before pagination
- Can be overridden by rules
Disable variant breakouts
Stop variant breakouts from expanding this block’s results into variant tiles, even when a breakout otherwise targets blocks. Behavior:- When on, the block always returns standard product tiles and skips variant breakout expansion for its results
- Applies to all block strategies
- Has no effect if no variant breakout is targeting blocks for the products in scope
- Toggle Disable Variant Breakouts on in the block’s Safeguards section
- Disabled by default. Blocks receive variant tiles when a variant breakout has Target blocks enabled
- Keep a “Frequently bought together” block at the product level while variant tiles appear elsewhere on the storefront
- Prevent duplicate-looking recommendations when a block anchor already represents a specific variant
- Preserve a fixed number of distinct products in a compact recommendation slot
Exclude family members
Hide other products that belong to the same product family as the block’s anchor product. This prevents a block from surfacing near-duplicates of the product a shopper is already looking at. Behavior:- Applies to all block strategies with a resolvable anchor product, including product-anchored blocks and collection-anchored similar-products blocks, where the collection resolves to a representative product
- Products sharing the anchor’s canonical family are removed from results before pagination
- Has no effect on products that aren’t assigned to a family
- Hide other color variations of the anchor on a “You may also like” block
- Prevent a “Similar products” block from returning the same style in a different fabric
- Keep cross-sell recommendations distinct from the current product
Family exclusion requires configured product families. Products with no family assignment are unaffected by this safeguard.
Exclude purchased products
Hide products the shopper has already purchased. This keeps recommendation rails focused on products the shopper doesn’t own yet. Behavior:- Every product in the shopper’s purchase history is added to the block’s exclusion set, alongside any family exclusions
- Purchase history comes from the
productsPurchasedarray in the request’s contextual information - Applies before pagination, so page counts reflect the excluded products
- Has no effect when the request includes no purchase history
- Toggle Hide products this shopper has already purchased on in the block’s Safeguards section
- Disabled by default
- Keep “You may also like” rails free of products the shopper already owns
- Avoid recommending one-time purchases the shopper has completed
- Focus cross-sell blocks on net-new products for returning customers
This safeguard requires purchase history in the API request’s context. Without it, results are unchanged. For replenishable products, use the Replenish strategy instead, which intentionally resurfaces past purchases.
Diversity cap
Limit how many products from the same family appear near the top of the block so the first results stay varied. When enabled, the block applies a per-family cap to its top window, similar to diversity expressions in sort orders. Behavior:- Available on all block strategies: interaction, similar products, manual (ids and collection), trending, and contextual
- Enforces the cap only within the top window of the block’s results; beyond the window, natural ordering resumes
- Layers on top of the block’s base ranking and never overrides a merchant-configured diversity rule already present in the underlying sort order
- Has no effect on products that aren’t assigned to a family
- Toggle Diversity Cap on in the block’s Safeguards section
- The cap is opt-in and disabled by default
- Prevent an interaction block from returning six variants of the same best-selling style at the top
- Keep a “Trending now” block visually varied when a single family dominates recent activity
- Ensure a collection-anchored similar-products block surfaces multiple distinct styles
Diversity requires configured product families. See Diversity expressions for a deeper explanation of how the top-window cap works.
Minimum products
If the block returns fewer than the minimum number of products, the fallback chain is used instead. The fallback mode decides whether the fallback replaces the primary results or tops them up. See Fallback Chains. Behavior:- Evaluated after filtering and safeguards are applied
- If results are below minimum, the system tries the first fallback block
- If no fallback blocks are configured, the block returns the available products
- Prevents displaying blocks with too few recommendations
- Ensure “Frequently Bought Together” always shows at least 4 products
- Maintain consistent block appearance across pages
- Automatically fall back to curated collections when behavioral data is insufficient
Maximum products
Limits the total number of products returned by the block across all pages. Behavior:- Applied after all filtering and sorting
- Caps the total result set to the specified maximum across all pages
totalResultsandtotalPagesreflect the capped total, ensuring consistent pagination metadata- Pages beyond the cap return empty results
- Limit recommendations to fit specific UI layouts
- Control page load performance
- Maintain consistent block sizes