# Conditions (in the element path)

**URL:** <https://forum.mergado.com/t/conditions-in-the-element-path/757>\
**Category:** Elements\
**Tags:** elements, element-path, conditions\
**Created:** [May 29, 2023, 1:39pm UTC](https://forum.mergado.com/t/conditions-in-the-element-path/757 "2023-05-29T13:39:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lehuy](https://forum.mergado.com/user_avatar/forum.mergado.com/lehuy/32/280_2.png) [@lehuy](https://forum.mergado.com/u/lehuy)\
**Post date:** [May 29, 2023, 1:39pm UTC](https://forum.mergado.com/t/conditions-in-the-element-path/757/1 "2023-05-29T13:39:22Z")

</div>

In this post, we will learn:

- [What are conditions?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-are-conditions-1)
- [What are conditions for?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-are-the-conditions-for-2)
- [How to write conditions correctly?](https://forum.mergado.com/t/conditions-in-the-element-path/757#correct-condition-notation-3)
- [What if an element has no children?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-if-an-element-has-no-children-4)
- [Most common uses](https://forum.mergado.com/t/conditions-in-the-element-path/757#most-common-uses-5)
- [Summary](https://forum.mergado.com/t/conditions-in-the-element-path/757#summary-9)

## What are conditions?

The _conditions_ in [element path](https://forum.mergado.com/t/element-path/753#what-is-path-to-element-2) are a filter that allows us to **filter values** and their elements within a given path. They are written in [curly brackets](https://en.wikipedia.org/wiki/Bracket) { } and bound to the element to the left of them. In conditions, you can filter **only through the elements [nested within the element](https://forum.mergado.com/t/nestedness/748)** to which the conditions bind.

A few **examples** you may have come across:

1. ![image](https://forum.mergado.com/uploads/default/original/1X/aadd4dfdba88d87669fdc192f348a6d838579f45.png)
2. ![image](https://forum.mergado.com/uploads/default/original/1X/11d95c2e3c75e3a3f29ddd2b921b8811bf9f0791.png)
3. ![image](https://forum.mergado.com/uploads/default/original/1X/3d5c152a6eab76bd867a70cfbc702ac402350715.png)

> ℹ &nbsp; The curly brackets { } are typed as follows on the Czech and Slovak keyboards: left bracket using right `Alt + B` or `Option + í` (Mac) and right bracket using right `Alt + N` or `Option + é` (Mac).   
> On the English keyboard they are typed as follows: left bracket using `Shift + [` and right bracket using `Shift +]`.

Let’s explain the **conditions with an example**. Let’s have the following data:

 ![image](https://forum.mergado.com/uploads/default/original/1X/3047612718da571eaa3278d9d0f5656582e8a7e6.png)

…i.e. with [element structure](https://forum.mergado.com/t/elements/501#element-in-mergado-editor-4) such that the PARAM element is the [parent](https://forum.mergado.com/t/nestedness/748#children-and-parents-4) and the PARAM\_NAME and VAL elements are its [children](https://forum.mergado.com/t/nestedness/748#children-and-parents-4). And let’s have the path from the first image in the introduction: `PARAM { PARAM_NAME = "Color" } | VAL`. In this path, the condition is `{ PARAM_NAME = "Color" }`. This condition binds to the parent PARAM element and is specified via the nested PARAM\_NAME element (which is also a child of the PARAM element).

 ![7c922120018878fdad64ffb1c7fd7bf914b2b7fa](https://forum.mergado.com/uploads/default/original/1X/12ebb9d125dc94fdbee4dd52a3576c64bca82337.png)

This [path with condition reads sequentially from left to right](https://forum.mergado.com/t/element-path/753#how-to-read-path-11) like this:  
Take a PARAM element whose underlying PARAM\_NAME element has a value equal to Color, and in such a PARAM element, target its child VAL.

![ezgif.com-gif-maker](https://forum.mergado.com/uploads/default/original/1X/b0e9d6a58a20a0f9fd15d85002aa9147a142d5da.gif)

And if we **break down the process into steps** , it looks like this:

1. We take the ([multi-value](https://forum.mergado.com/t/what-is-a-multi-value-element/589)) parent element PARAM…  
path reading: ![Screenshot from 2023-06-06 09-40-50](https://forum.mergado.com/uploads/default/original/1X/bfad75b6dbf5123e7007e3d5d4e93c86b15c33a1.png)

 ![1](https://forum.mergado.com/uploads/default/original/1X/58838d258540e0ef6d019479ae9b381143ab71ef.png)

1. …whose nested PARAM\_NAME element has the value Color…  
path reading: ![Screenshot from 2023-06-06 09-40-57](https://forum.mergado.com/uploads/default/original/1X/2a33f320d5c562455efb0e15880f9da170849cc2.png)

 ![2](https://forum.mergado.com/uploads/default/original/1X/c21b4777882ad8b798c64517f3ae85d7a52ee068.png)

1. …and in such a PARAM element we target the (multiple) VAL element.  
path reading: ![Screenshot from 2023-06-06 09-41-02](https://forum.mergado.com/uploads/default/original/1X/a13a949a548a6562e85325ddca81113700285e4d.png)

 ![3](https://forum.mergado.com/uploads/default/original/1X/1f24f218f879a578bd9611b709251eb15c2c3e50.png)

So the `PARAM { PARAM_NAME = "Color" } | VAL` path filters and targets only those VAL elements that have PARAM\_NAME elements with Color as [sibling](https://forum.mergado.com/t/nestedness/748#children-and-parents-4).

## What are the conditions for?

![ezgif-4-09100b9b24](https://forum.mergado.com/uploads/default/original/1X/f9a52b221498cbfc710d1cb11ca189d8a2e8cadb.gif)

As we mentioned earlier, the conditions in the element path are a filter. The **conditions refine the specified path** and allow you to target a more specific subset of the element’s values.

Let’s take an **example** :  
Consider a product with [parameters](https://forum.mergado.cz/t/prace-s-parametry-v-mergadu-2/2249) Size, Color, Material, and Gender. Let’s say we want to override Size from the original value of “XXL” to “M”. How do we do it? We know that we target the parameter values using the `PARAM | VAL` path, which is a path without a condition:

 ![3 (copy)](https://forum.mergado.com/uploads/default/original/1X/2560012a12f0932a872825cb33de2dd449db2ef1.png)

Well yeah, but we only want to override (target) the value “XXL” for the Size parameter. The conditions will help us to do that! The conditioned path then looks like this:

`PARAM { PARAM_NAME = "Size" } | VAL`

 ![original (copy)](https://forum.mergado.com/uploads/default/original/1X/a265f0f734d0ded41e8504d64801eb855105eb44.png)

**Conditions are only worth using for [multi-value](https://forum.mergado.com/t/what-is-a-multi-value-element/589) elements**. You can use conditions for simple elements too, but it misses the point of the element’s simplicity - such elements _have only one value_, so there is no reason and nothing to filter from.

> ℹ &nbsp;In Mergado 1, conditions didn’t exist and couldn’t be worked with, as there were no [multi-value](https://forum.mergado.com/t/what-is-a-multi-value-element/589) elements or [element structure](https://forum.mergado.com/t/elements/501#element-in-mergado-editor-4) in that version.

## Correct condition notation

Let’s have a path `PARAM { PARAM_NAME = "Color" } | VAL`. The **basic template** for writing a condition is:

 ![Screenshot from 2023-06-08 07-49-39](https://forum.mergado.com/uploads/default/original/1X/206317e669e609668c1c2807a2811f76f8763d1e.png)

> 💡 Spaces are important and can’t be left out! Both spaces in the condition itself and spaces before and after the condition.

The content of the condition resembles the query form for [custom MQL query](https://forum.mergado.com/t/advanced-search/474). The first image from the introduction is from the same place.

 ![image](https://forum.mergado.com/uploads/default/original/1X/38dd04f9ba0678ea84c7ab2a7f331651dc1670b6.png)

And it’s no coincidence. In fact, **we can type absolutely anything into the conditions of an [MQL](https://forum.mergado.com/t/mql-language/755) query**. This opens up a world of incredible possibilities. For example, an MQL query for the values of the variant parameters Size and Material

![image](https://forum.mergado.com/uploads/default/original/1X/d95c235ac1e0fbff997d5dc1680023c2510d0ddc.png)

goes into the path condition that targets the store name

`VARIANTS | VARIANT ``{ PARAMETERS | PARAMETER { NAME = "Size" } | VALUE = "M" AND PARAMETERS | PARAMETER { NAME = "Material" } | VALUE = "Cotton" }`` | STOCK | WAREHOUSES | WAREHOUSE | NAME`

By defining the condition, only variants whose value of the Size parameter is M and at the same time the value of the Material parameter is Cotton are filtered out. In this example, we see that **there can be other conditions and [operators](https://forum.mergado.com/t/mql-language/755#the-condition-consists-of-3-parts-5)** in one condition and that we can work with arbitrarily nested elements.

> ℹ &nbsp;There are conditions in the element path and conditions in [MQL](https://forum.mergado.com/t/mql-language/755). Meaningfully, **they are two different things** , even though they are called the same. A condition in the element path starts and ends with curly brackets { } and a condition in MQL consists of 3 parts. There can be multiple MQL conditions in an element path condition.

 ![Screenshot from 2023-06-06 10-24-55](https://forum.mergado.com/uploads/default/original/1X/584ecf6fe2521560e136212ed4f1653f3842b74e.png)

## What if an element has no children?

In the [What are conditions?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-are-conditions-1) section, we said that conditions are bound to the parent element and that in conditions you can only work with nested elements. What if an element has no children and no nested elements? Can conditions be used for such elements as well? Yes, they can.

There are [special attributes](https://forum.mergado.com/t/special-attributes/749) [@@POSITION](https://forum.mergado.com/t/position/766) and [@@VALUE](https://forum.mergado.com/t/value/751) (we will add more in the future). These attributes are also bound to the element and can therefore be used in conditions.

Let’s give an **example** :  
Let’s have the following data:

![image](https://forum.mergado.com/uploads/default/original/1X/6c5d64165244ff7f0e13563c6b26e4258b1b4492.png)

We have a [multi-value](https://forum.mergado.com/t/what-is-a-multi-value-element/589) IMGURL\_ALTERNATIVE element with 3 values. How do we target its second value?

![image](https://forum.mergado.com/uploads/default/original/1X/ba23ff236582ca86e650f56044295beefb1d9355.png)

The answer is the third image from [introduction](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-are-conditions-1):

![image](https://forum.mergado.com/uploads/default/original/1X/892712145aaab2fc01cc7cc5ded47a6a8226569a.png)

After the element, just **type a condition with the special attribute** `@@POSITION = 2` and such a path will only target the IMGURL\_ALTERNATIVE element whose position is two.

Another way may be to use the special attribute @@VALUE:

![image](https://forum.mergado.com/uploads/default/original/1X/3d5c152a6eab76bd867a70cfbc702ac402350715.png)

which filters out only IMGURL\_ALTERNATIVE elements that have a value equal to `https://picsum.photos/400/300`. However, this method of targeting the second value **works only if the element does not take the value multiple times**. Otherwise, the path targets all such values, i.e. not just the second value.

## Most common uses

In general, conditions can be **applied to any element** (and especially multi-value elements). In this section, we will give some examples that we have encountered in practice. For clarity, we mark the condition in yellow in the examples.

### 1. Parameters and deliveries

Clearly **the most common use of conditions is for parameters and deliveries**. We have been working with one such example throughout this post:

`PARAM``{ PARAM_NAME = "Color" }`` | VAL`

This is a path that **targets the value of the parameter** Color, with elements from [Heureka format specification](https://sluzby.heureka.cz/napoveda/xml-feed/) or [Zboží](https://napoveda.zbozi.cz/xml-feed/specifikace/). Similar paths for other formats:

- [Shoptet](https://www.shoptet.cz/export/schema/products-complete-v10.rng): `TEXT_PROPERTIES | TEXT_PROPERTY ``{ NAME = "Color" }`` | VALUE`
- Shoptet, filtering parameters: `INFORMATION_PARAMETERS | INFORMATION_PARAMETER ``{ NAME = "Color" }`` | VALUE`
- [Google](https://support.google.com/merchants/answer/7052112?hl=en): `g:product_detail ``{ g:attribute_name = "Color" }`` | g:attribute_value`

For delivery, e.g. a path is used to target a price for a particular carrier:

`DELIVERY ``{ DELIVERY_ID = "PPL" }`` | DELIVERY_PRICE_COD`

> 💡 Parameters and deliveries are **whisperable** in the Mergado Editor.
> 
> ![image](https://forum.mergado.com/uploads/default/original/1X/08cd52befd9d778a998d27eb8a61ef291ad6a6af.png)

### 2. Variants

Since there are usually more variants and we want to work with variants efficiently and effectively, we cannot avoid using conditions. Usually we will want to **target some specific variants**.  
For example, a variant whose some element takes on some particular value. We gave one example in the [Correct condition notation](https://forum.mergado.com/t/conditions-in-the-element-path/757#correct-condition-notation-3) section.

`VARIANTS | VARIANT ``{ PARAMETERS | PARAMETER { NAME = "Size" } | VALUE = "M" AND PARAMETERS | PARAMETER { NAME = "Material" } | VALUE = "Cotton" }`` | STOCK | WAREHOUSES | WAREHOUSE | NAME`

> ℹ &nbsp;Some users also use a special [@@POSITION](https://forum.mergado.com/t/position/766) attribute to target specific variants.

### 3. Image URLs and categories

Some products may have multiple images. To **target a specific image** or group of images, use [@@POSITION](https://forum.mergado.com/t/position/766) or [@@VALUE](https://forum.mergado.com/t/value/751) and the appropriate operators. We gave one example in [What if an element has no children?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-if-an-element-has-no-children-4), other examples include

- `IMGURL_ALTERNATIVE ``{ @@POSITION >= 3 }`
- `IMGURL_ALTERNATIVE ``{ @@POSITION >= 3 AND @@POSITION <= 8 }`
- `IMGURL_ALTERNATIVE ``{ @@VALUE != "https://picsum.photos/400/300" }`

Less often, but it does happen, products can have multiple categories, e.g. the Shoptet format does.

![image](https://forum.mergado.com/uploads/default/original/1X/86ff4a1c1684fd4c1907c5830d0d653b43fdab1a.png)

If we want to **target a specific category** , or group of categories, we again use @@POSITION or @@VALUE and the appropriate operators for them. For example:

- `CATEGORIES | CATEGORY ``{ @@POSITION < 3 }`
- `CATEGORIES | CATEGORY ``{ @@VALUE NOT CONTAINS "Playgrounds" }`

## Summary

- [What are conditions?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-are-conditions-1)  
Conditions in [path to an element](https://forum.mergado.com/t/element-path/753#what-is-path-to-element-2) are a filter that allows us to filter values and their elements within a given path. They are written in curly brackets { } and are bound to the element to the left of them. In conditions, you can only filter through the [nested](https://forum.mergado.com/t/nestedness/748) elements in the element to which the conditions are bound.

- [What are conditions for?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-are-the-conditions-for-2)  
Conditions refine the specified path, allowing you to target a more specific subset of the element’s values.

- [How do you write conditions correctly?](https://forum.mergado.com/t/conditions-in-the-element-path/757#correct-condition-notation-3)  
Let’s have a path `PARAM { PARAM_NAME = "Color" } | VAL`. The basic template for writing a condition is:  
&nbsp;  

- [What if an element has no children?](https://forum.mergado.com/t/conditions-in-the-element-path/757#what-if-an-element-has-no-children-4)  
Even for such elements you can use conditions. There are [special attributes](https://forum.mergado.com/t/special-attributes/749) that are bound to the element and can be used in conditions.

- [Most common uses](https://forum.mergado.com/t/conditions-in-the-element-path/757#most-common-uses-5)  
The most common use of conditions in an element path is when working with parameters, deliveries, variants, categories, and image URLs.
