Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Migration guide
vtex.condition-layout
Version: 2.8.2
Latest version: 2.8.2

If you're currently using the Condition Layout in its 1.x.x version, the following guide aims to help you to perform a version upgrade, migrating your store theme to the latest version of the app (2.x.x).

If you’re using the former version, you can still find its documentation here. Do not forget to also access the Condition Layout current documentation for its 2.x.x version.

:information_source: Although support for the former version is still granted, we strongly recommend you to update your store theme with the app's newest version in order to keep up with the components' evolution.

Overview

The rewriting of this app aimed to provide a clearer logic when setting the conditions to build the new desired layout.

The changes included in the app upgrade are, namely:

Block structure

In the 1.x.x version, the condition-layout app exports three different types of blocks for your store theme:

  • condition-layout.product - Wraps the desired condition.product blocks.
  • condition.product - Defines the desired conditions to be met.
  • condition.else - Defines in its child blocks a component to be rendered in case no condition is met.

_40
{
_40
"store.product": {
_40
"children": ["condition-layout.product"]
_40
},
_40
"condition-layout.product": {
_40
"children": [
_40
"condition.product#custom-pdp-12",
_40
"condition.product#custom-pdp-20",
_40
"condition.else"
_40
]
_40
},
_40
"condition.product#custom-pdp-12": {
_40
"props": {
_40
"conditions": [
_40
{
_40
"subject": "productId",
_40
"verb": "is",
_40
"object": "12"
_40
}
_40
]
_40
},
_40
"children": ["flex-layout.row#custom-pdp-layout-12"]
_40
},
_40
"condition.product#custom-pdp-20": {
_40
"props": {
_40
"conditions": [
_40
{
_40
"subject": "productId",
_40
"verb": "is",
_40
"object": "20"
_40
}
_40
]
_40
},
_40
"children": ["flex-layout.row#custom-pdp-layout-20"]
_40
},
_40
_40
"condition.else": {
_40
"children": ["flex-layout.row#default"]
_40
}
_40
}

The block configuration is simplified in the 2.x.x version: now, all three blocks were merged into a single one called condition-layout.product.

The same structure above can now be rewritten using the new block's props:


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

Prop's syntax

In 1.x.x, a simple logic for creating conditions was provided, where you could mix the subject, verb, and object props to set conditions in an idiomatic way.

Since it provided a very effortless and easy syntax to set conditions, these last ones were, in turn, very limited as well. For example, it was not possible to check for a specification property name and value at the sime time.


_16
{
_16
"condition.product": {
_16
"props": {
_16
"conditions": [
_16
// checks if the product has the
_16
// specification named `Material`
_16
{
_16
"subject": "specificationProperties",
_16
"verb": "contains",
_16
"object": "Material"
_16
}
_16
]
_16
},
_16
"children": ["..."]
_16
}
_16
}

In 2.x.x, the aforementioned syntax was replaced with a pair of subject and arguments props.

In practice, a subject is linked to an internal method that receives the arguments. Make sure to check which arguments each subject can receive in the Condition Layout documentation.

The above condition can be rewritten in the app's newest version as:


_19
{
_19
"condition.product": {
_19
"props": {
_19
"conditions": [
_19
// checks if the product has the
_19
// specification named `Material`
_19
{
_19
"subject": "specificationProperties",
_19
"arguments": {
_19
"name": "Material"
_19
// Optional: could also check for its value
_19
// "value": "Leather"
_19
}
_19
}
_19
],
_19
"Then": "..."
_19
}
_19
}
_19
}

Negative conditions

Previously (1.x.x), negative conditions were built using the is-not and does-not-contain values from the verb prop, as shown below:


_14
{
_14
"condition.product": {
_14
"props": {
_14
"conditions": [
_14
{
_14
"subject": "specificationProperties",
_14
"verb": "does-not-contain",
_14
"object": "Material"
_14
}
_14
]
_14
},
_14
"children": ["..."]
_14
}
_14
}

In the latest version (2.x.x), the verb prop has given way to the toBe prop, which assigns in its value (true or false) the expected value of the condition.

The above condition can be rewritten as:


_16
{
_16
"condition.product": {
_16
"props": {
_16
"conditions": [
_16
{
_16
"subject": "specificationProperties",
_16
"arguments": {
_16
"name": "Material"
_16
},
_16
"toBe": false
_16
}
_16
],
_16
"Then": "..."
_16
}
_16
}
_16
}

See also
Vtex.condition Layout
VTEX IO Apps
VTEX App Store
VTEX IO Apps