Conditional variables

To display values (variables, text, image, etc.) according to conditions in the newsletter.

Benjamin Carro avatar
Écrit par Benjamin Carro
Updated over a week ago

Displaying values according to conditions can be very useful, that's why you can add conditional variables in the newsletter.
Concretely, the value of the variable will be displayed if it is present in the metadata. Conversely, if the value of the variable is set to "False" or does not exist, then it will not be displayed in the newsletter.

You can use conditional variables on all types of variables available in the template editor namely :

  • Editor variables

  • Global variables

  • Item Variables

How to use conditional variables?

To display or not a value depending on the availability of a value in the metadata, you have to use the syntax below :

The display condition is defined with the # symbol like this {{#variable}} then, you have to insert the value, which must be displayed (variable, text, image, symbol, etc.) if the value exists, then you have to close the condition with the / symbol like this {{/variable}}.

The conditional variable must look like this :

{{#variable}} {{variable}} {{/variable}}


Example of a conditional variable displaying static text :

{{#variable}} Insert static text here {{/variable}}

Good to know:
The function will be valid even if you insert spaces before the brackets as in the example below:

{{ #variable }} {{ variable }} {{ /variable }}


Small subtlety, to call an HTML variable, you need three braces at the beginning and at the end, like here:

{{ #variable }} {{variableWhichContainsHTML}} {{ /variable }}
Avez-vous trouvé la réponse à votre question ?