Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Layout Apps
Condition Layout
Official extension
Version: 1.1.6
Latest version: 2.8.2

This page is about version 1.1.6 of the app, which is not the most recent version. The latest stable version is 2.8.2.

The condition layout app allows to conditionally render a block given certain conditions.

{"base64":"  ","img":{"width":742,"height":1504,"type":"gif","mime":"image/gif","wUnits":"px","hUnits":"px","length":871202,"url":"https://user-images.githubusercontent.com/12139385/79379694-a8c99980-7f35-11ea-9f01-7021c6529332.gif"}}

Configuration

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

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


_10
"dependencies": {
_10
"vtex.condition-layout": "1.x"
_10
}

Step 2 - Adding the Condition Layout's blocks to your theme's templates

The condition-layout app exports two kinds of block: condition-layout.{context} and condition.{context}.

  • condition-layout.{context} - These blocks are responsible for holding your condition blocks and providing the appropriate context.
  • condition.{context} - These blocks hold the condition logic and children to be displayed given the condition resolves to true.
  • condition.else - This block can be used to render some content if no condition block was matched inside a condition.layout. The usage of this block is optional. If no condition is matched and there's no condition.else declared, nothing will be shown.

condition-layout

Each variant of a condition-layout is responsible for providing the values to be used in comparisons by its subsequent condition blocks.

You should never use condition-layout directly. Make sure to always use a context variant, such as condition-layout.product.

condition-layout.product

The condition-layout.product block provides the subjects below to use in condition.{context} blocks.

SubjectTypeDescription
productIdvalueId of the current product.
categoryIdvalueId of the current category.
brandIdvalueId of the current brand.
selectedItemIdvalueId of the current selected SKU
productClustersarrayList of product clusters.
categoryTreearrayList of categories.

condition.{context}

Prop nameTypeDescription
conditionsConditionArrayA list of conditions to be resolved
matchMatchTypeThe condition list match type
childrenReactNodeThe children component(s) to be rendered when the condition matches.

Types

ConditionArray

Prop nameTypeDescription
subjectstringSubject ID to get its value.
verbConditionVerbThe condition operator.
objectstringThe value to be compared with the subject's value.

ConditionVerb

For subjects of type value, there are two verbs available:

TypeDescription
isChecks for equality (default for value subjects).
is-notChecks for inequality.

For subjects of type array, there are two verbs available:

TypeDescription
containsChecks if the subject's value contains the defined object (default for array subjects).
does-not-containChecks if the subject's value does NOT contain the defined object.

MatchType

TypeDescription
allResolves a list of conditions to true only if all conditions match (default).
anyResolves a list of conditions to true if any of the conditions match.
noneResolves a list of conditions to true if NONE condition match.

Example

Checking for a specific product ID


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

See also
VTEX App Store
VTEX IO Apps