# Add variables to a message templates

A variable is a placeholder that represents a specific piece of data that is automatically inserted into the message template when it is sent.

## Add variables to a message template

{% hint style="info" %}
Variable names are limited to alphanumeric characters, periods (.), underscores (\_), and hyphens (-).
{% endhint %}

* Go to **Marketing > Content > Message templates**.
* Create a new message template, or edit a published message template.
* Go to **Settings**, then click the **Variables** tab.

<figure><img src="/files/PYmcEZHBUIAaclkdZ7NJ" alt=""><figcaption></figcaption></figure>

* Click **Add new variable**.
* In the **Name** field, type the name of your variable, such as `firstname`.
* In the **Description** field, type a variable description to explain its purpose to your team.
* Provide a sample value for the variable in every language that the template supports. For example, if the variable is `drinkType`, include "Coffee" for English and "Koffie" for Dutch.
* Click **Save**.

Note that the sample value should be a static value a variable can have, this is preview and for approval (WhatsApp only) purposes and doesn't indicate the final dynamic value it will show on sending. The mapping of the variable with the dynamic value will happen when building a campaign or journey.

<figure><img src="/files/Uj0iGSBv9SoHV6wuplXX" alt="" width="375"><figcaption></figcaption></figure>

* Once the variable is saved, you can go back to the Editor and add the variable to the text where needed by clicking on **{ }** icon

<figure><img src="/files/wSsuFGl1wkA1SnHvlj2s" alt="" width="375"><figcaption></figcaption></figure>

* Once added, variables will appear as a placeholder as shown below in the editor

<figure><img src="/files/oO2jAtKrvQ0LT8u2Vm9s" alt="" width="375"><figcaption></figcaption></figure>

* In the preview tab, you can view the template with the sample value

<figure><img src="/files/dSe7Y7SBqOArNLLm8Pt5" alt="" width="375"><figcaption></figcaption></figure>

* You can now publish your template and add it to a campaign or journey, where you will be asked to map the template variable with a dynamic value.

#### Mapping variables in Campaigns

* When you select a template with variables in the Campaign content section, you will see a Variable Matching section below the template which will show the list of variables in the template to be mapped

<figure><img src="/files/5H5tdM7mN0yHgkWmO9g3" alt=""><figcaption></figcaption></figure>

* In this section, under **Value** type of select the dynamic value to map with the variable
  * For example, you can directly search for the contact attribute and add it

<figure><img src="/files/24ss7kF8NCB6sGGXESfA" alt="" width="375"><figcaption></figcaption></figure>

* Or you can go to **Contact** in the dropdown

<figure><img src="/files/rrhFd8bqN8JBGQsNaYzU" alt="" width="375"><figcaption></figcaption></figure>

* Select the contact attribute to which you want to map the variable with

<figure><img src="/files/0ymO6vxw2hQp8Wc2ROtu" alt="" width="375"><figcaption></figcaption></figure>

* Once the value is set, you also need to define a **default value** if the contact attribute value for a contact is empty

<figure><img src="/files/IgXQVP0iTxIoMkWDyBPn" alt=""><figcaption></figcaption></figure>

#### Mapping variables in Journeys

* In Journeys, first add the Send Message step and select to add/create a template
* Once you have added a template where variables are defined, you will be asked to map the variables under the Template variables section below the content section

<figure><img src="/files/lkfyYGr2pMO366aEDBiw" alt="" width="375"><figcaption></figcaption></figure>

* You can now either type in the variable value format (contact.attributes.firstName) or select a variable value to map from the dropdown
  * You can directly search for the contact attribute name if you are mapping with one

<figure><img src="/files/6QX8wixwqzABzj9Ahkwq" alt="" width="375"><figcaption></figcaption></figure>

* You can also select Contact from the dropdown

<figure><img src="/files/hl0enfns0oCVrzKTo2AJ" alt="" width="371"><figcaption></figcaption></figure>

* Select the contact attribute to map the variable with

<figure><img src="/files/CRnpFCAZDAL8ndNJINlg" alt="" width="375"><figcaption></figcaption></figure>

* Once the variable value is selected, you need to provide. default when it is empty&#x20;

<figure><img src="/files/UIsT454nDuSF2nYHlHif" alt="" width="375"><figcaption></figcaption></figure>

* If you are using event triggers for journeys like Cart Updated, you can also map the variables with event properties like Checkout URL
* Select **Event** from the dropdown when mapping a variable

<figure><img src="/files/bL60ysczoXkN91JuTuWW" alt="" width="375"><figcaption></figcaption></figure>

* Select the event property from the dropdown like Checkout URL.&#x20;

<figure><img src="/files/yHAs0RAnfWW7pK3gPu96" alt="" width="375"><figcaption></figcaption></figure>

* You can also directly type the event property format in place of selecting from the dropdown e.g. `{{event.properties.checkout_url}}`&#x20;
* Once the variable value is selected, you need to provide. default when it is empty&#x20;

<figure><img src="/files/sNCEYMFWm35rcpXMwAmj" alt="" width="375"><figcaption></figcaption></figure>

* You can now **Save** the changes to the Send message step and publish your journey.

#### Sending message with variables mapped

* When sending to a contact with a variable mapped to **contact attribute**, the value of the variable will be picked from what is stored on their selected contact attribute you mapped it with
* If the value is empty on the contact attribute on a contact, they will receive the message with default value

<figure><img src="/files/riE46JcI96353I6PVzpI" alt=""><figcaption></figcaption></figure>

* When mapping to **event properties,** the value for the variable is picked from the trigger event in the journey. You can view this on an individual run as trigger payload.
  * You can first go to the Runs page

<figure><img src="/files/UEgKaBKqXHZkaVbB4rrx" alt="" width="375"><figcaption></figcaption></figure>

* Then click on a run and view the details of event properties in  the trigger

<figure><img src="/files/SdzlF69yNodsT0wRaT82" alt=""><figcaption></figcaption></figure>

* You can also view some event properties on the event timeline of a contact as well

<figure><img src="/files/xzu8awIzzu6OCc0i2xzc" alt="" width="375"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bird.com/applications/content/message-templates/how-to/add-variables-to-a-message-templates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
