IO Base Component

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

⚠️

*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.

Condition Layout

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

Configuration

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:

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"]
  },
}

Or the condition-layout.binding block, for example:

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

Or the condition-layout.category block, for example:

{
  "store.search#my-category-page": {
    "children": ["condition-layout.category"]
  }
}

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"
+   }
+ }
}

Or for condition-layout.binding:

{
  "store.product": {
    "children": ["condition-layout.binding#cond42"]
  },
  "condition-layout.binding#cond42": {
+   "props": {
+     "conditions": [
+       {
+         "subject": "bindingId",
+         "arguments": {
+           "id": "13fb71d0-binding-code-here-87h9c28h9013"
+         }
+       }
+     ]
+     "Then": "flex-layout.row#just-for-this-binding",
+     "Else": "flex-layout.row#for-other-bindings"
+   }
+ }
}

Or for condition-layout.category:

{
  "store.product": {
    "children": ["condition-layout.category#cond42"]
  },
  "condition-layout.category#cond42": {
+   "props": {
+     "conditions": [
+       {
+         "subject": "department",
+         "arguments": {
+           "ids": ["1", "42"]
+         }
+       }
+       {
+         "subject": "category",
+         "arguments": {
+           "ids": ["301", "304"]
+         }
+       }
+     ]
+     "matchType": "any",
+     "Then": "flex-layout.row#just-for-this-category-or-department",
+     "Else": "flex-layout.row#for-other-category-or-department"
+   }
+ }
}
  • conditions object:

Possible values for the condition-layout.product's subject prop:

Possible values for the condition-layout.binding's subject prop:

Possible values for the condition-layout.category's subject prop:

Possible values for the condition-layout.user's subject prop:

Modus Operandi

The condition-layout.product mainly uses the matchType 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 matchType prop has the responsibility for deciding the necessary number of valid conditions for the layout rendering to actually occur.

Customization

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!

Last updated