VTEX Developer Portal

📢 Use this project, contribute to it or open issues to help evolve it using Store Discussion.

Condition Layout

All ContributorsAll Contributors

The Condition Layout app allows a component to be rendered in your store if predefined conditions are met.



:warning: *Condition Layout app v1 has been deprecated in favor of Condition Layout app v2. Although support for the former version is still granted, we strongly recommend you to access the Migration Guide and update your store theme with the app's newest version in order to keep up with the components' evolution. If you’re still using the former version, you can find its documentation here.*

Step 1 - Adding the Condition Layout app to your theme's dependencies

In your theme's manifest.json, add the Condition Layout app as a dependency:

"dependencies": {
+   "vtex.condition-layout": "2.x"

You are now able to use all blocks that are exported by the condition-layout app. Check out the full list below:

Block nameDescription
condition-layout.productDefines the condition logic and the children blocks that are going to be rendered in case the predefined conditions are met.

Step 2 - Adding the condition-layout.product block to your theme's templates

In the product theme template, add the condition-layout.product block as a children. For example:

  "store.product": {
    "children": ["condition-layout.product"]

:warning: Never use condition-layout directly. Make sure to always use it with the context variant, such as condition-layout.product.

Step 3 - Defining the desired conditions

Now it is time to configure the condition-layout.product block!

Use the block's props to define your layout condition. You can also declare as the children the condition-layout.product's children some blocks of your choosing to be rendered if the condition is met.

For example:

  "store.product": {
    "children": ["condition-layout.product#cond1"]
  "condition-layout.product#cond1": {
+   "props": {
+     "conditions": [
+       {
+         "subject": "productId",
+         "arguments": {
+           "id": "12"
+         }
+       },
+     ]
+     "Then": "flex-layout.row#custom-pdp-layout-12",
+     "Else": "flex-layout.row#default"
+   },
+ },

:information_source: According to the example above, whenever users interact with a product whose ID is equal to 12, the block flex-layout.row#custom-pdp-layout-12 is rendered. If users interact with a product whose ID is not equal to 12, the rendered block is the flex-layout.row#default.

Prop nameTypeDescriptionDefault value
conditionsobjectList of desired conditions.undefined
matchenumLayout rendering criteria. Possible values are: all (all conditions must be matched in order to render the layout), any (at least one of the conditions must be matched in order to render the layout) or none (no conditions must be matched in order to render the layout).all
ThenblockName of the block to be rendered if the conditions are met. If no value is defined, the blocks declared as children of condition-layout.product will be rendered instead.undefined
ElseblockName of the block to be rendered if the conditions are not met.undefined
  • conditions object:
Prop nameTypeDescriptionDefault value
subjectstringDefines, according to the product context where the block in declared in, which data is needed from the UI to validate the value chosen in the object prop. Check below the possible values for this prop.undefined
argumentsobjectDefines the condition parameters. Notice: this prop value varies according to the value set to the subject prop. Check below the table for the subject's possible values and their expected arguments.undefined
toBebooleanWhether the data fetched in the subject prop must met the predefined conditions to render the new layout (true) or not (false).true

Possible values for the subject prop:

productIdProduct's IDs currently displayed on the UI.{ id: string }
categoryIdCategory's IDs currently displayed on the UI.{ id: string }
brandIdBrand's IDs currently displayed on the UI.{ id: string }
selectedItemIdID of the item currently selected by the user.{ id: string }
productClustersList of product clusters currently displayed on the UI.{ id: string }
categoryTreeList of categories currentluy displayed on the UI.{ id: string }
specificationPropertiesList of product specifications currently displayed on the UI.{ name: string, value: string }. Notice: value is an optional prop. If omitted, only the specification name (name) will be checked.
areAllVariationsSelectedWhether all product variations currently available on the UI were selected by the user (true) or not (false).No arguments are expected.
isProductAvailableWhether the product is available (true) or not (false).No arguments are expected.

Modus Operandi

The condition-layout.product mainly uses the match and conditions props to set, respectively, the criteria and the conditions that blocks must meet to be rendered or not.

The conditions prop, in turn, does not rely on any automatic grammar to define the desired conditions. Instead, it relies on its two props, namely subject and arguments, that together define which condition must be met by using an underlying data validation method (with specific arguments) according to the UI behavior.

Lastly, the match prop has the responsibility for deciding the necessary number of valid conditions for the layout rendering to actually occur.


The Condition Layout merely establishes a logic to render other blocks. Therefore, the app doesn't have CSS Handles for its specific customization.

Instead, you should use its child block's Handles.

Contributors ✨

Thanks goes out to these wonderful people:

This project follows the all-contributors specification. Contributions of any kind are welcome!

Updated 28 days ago

Condition Layout

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.