> ## Documentation Index
> Fetch the complete documentation index at: https://help.chatarmin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditional rendering of Variables in Messages & Campaigns

> Chatarmin guide: Conditional rendering of Variables in Messages & Campaigns

Welcome to the Template Engine Guide. This document will help you understand how to use our template engine for dynamic content generation. The template engine supports various conditional statements and loops to customize your templates effectively.

# Where can this be used?

**In Flow Messages:**

<img src="https://mintcdn.com/chatarmin-help-center/NyfZxeNHFMDFfmtq/images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-a9e5-762c-b5ce-ce163a48f7d4.png?fit=max&auto=format&n=NyfZxeNHFMDFfmtq&q=85&s=d02e3bcebe87731b0771b11ecba59070" alt="Chatarmin help center image" width="1024" height="604" data-path="images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-a9e5-762c-b5ce-ce163a48f7d4.png" />

**In Campaigns/Templates:**

<img src="https://mintcdn.com/chatarmin-help-center/NyfZxeNHFMDFfmtq/images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-aa2e-732e-8d72-115535de6563.png?fit=max&auto=format&n=NyfZxeNHFMDFfmtq&q=85&s=44db06d6eb778315b21a1625e4f64cee" alt="Chatarmin help center image" width="1024" height="665" data-path="images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-aa2e-732e-8d72-115535de6563.png" />

# Syntax

Currently, there are two options to make use of conditional rendering:

* If/Else rendering
* For loop / List rendering

## If/Else rendering

The syntax for this looks like so:

```
#&#123;&#123;if contact.firstname contains 'dog' then 'Doglover' else 'Catlover'&#125;&#125;
```

So the structure would be: **if \<Variable> \<Condition> then '\<Text>' else '\<Text>'**

### Different types of Conditions:

1. **contains:**\
   Example:`#&#123;&#123;if contact.firstname contains 'dog' then 'Doglover' else 'Catlover'&#125;&#125;`

2. **isTrue:**\
   Example:`#&#123;&#123;if contact.dog isTrue then 'Doglover' else 'Catlover'&#125;&#125;`

3. **isEmpty**: e.g.\
   Example: `#&#123;&#123;if apiPayload.food isEmpty then 'No Food' else 'Still food'&#125;&#125;`

4. **equals**:\
   Example: `#&#123;&#123;if contact.pet equals 'dog' then 'DOG' else 'CAT'&#125;&#125;`

## For loop / List rendering

Here, the syntax look like so:

```
#&#123;&#123;for item in contact.properties.items&#125;&#125;

 <!-- Content to repeat for each item -->

#&#123;&#123;/each&#125;&#125;
```

Here, I could for example also combine the above if/else inside the For Loop:

```
#&#123;&#123;for item in contact.properties.items&#125;&#125;

  #&#123;&#123;if item contains 'dog' then 'Doglover' else 'Catlover'&#125;&#125; 

#&#123;&#123;/each&#125;&#125;
```

## Accessing Variables

When setting Variables through the Dropdown in Campaigns:

<img src="https://mintcdn.com/chatarmin-help-center/NyfZxeNHFMDFfmtq/images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-aa2f-76ac-ad1d-35ceae5552c6.png?fit=max&auto=format&n=NyfZxeNHFMDFfmtq&q=85&s=4900dc2f78c47b6aa28f293c696329fa" alt="Chatarmin help center image" width="1024" height="646" data-path="images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-aa2f-76ac-ad1d-35ceae5552c6.png" />

You can see, how you can access which exact properties.

In "normal Messages" of a Flow, you can see them, when you type in "@" in the Textinput:

<img src="https://mintcdn.com/chatarmin-help-center/NyfZxeNHFMDFfmtq/images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-a9f1-724c-a9a9-83e105754cc1.png?fit=max&auto=format&n=NyfZxeNHFMDFfmtq&q=85&s=f7ccfe6cce24ea3e5e454749476f1a8b" alt="Chatarmin help center image" width="1024" height="488" data-path="images/d8868e59-4057-4645-b054-b1ffee0aae67/019b9c80-a9f1-724c-a9a9-83e105754cc1.png" />

# Examples

Here are some examples and their outputs so you can get a bit of a feeling:

### Example 1

```
TEXT:

#&#123;&#123;for item in contact.properties.items&#125;&#125;

 #&#123;&#123;item.quantity&#125;&#125; x #&#123;&#123;item.price&#125;&#125;

#&#123;&#123;/each&#125;&#125;
```

```
WHEN:
contact.properties.items => [&#123;quantity:2, price: "50€"&#125;]

OUTPUT:

2 x 50€
```

### Example 2

```
TEXT:

#&#123;&#123;if item contains 'dog' then 'Doglover' else 'Catlover'&#125;&#125;
```

```
WHEN:
item => "cats"

OUTPUT:

Catlover
```

### Example 3

You can also use nested/multiple if/else:

```
#&#123;&#123;if contact.isActive isTrue then "Active" else #&#123;&#123;if contact.firstname contains 'cat' then 'CAT Lover' else 'Inactive'&#125;&#125;&#125;&#125;
```
