# Using variables

You can easily customize your responses or templates with dynamic content like your recipient's name by using our variables templating engine.

A response like this:

```liquid
Hi {{ recipient.first_name | default: 'there' }},
```

… if it matches a `recipient.first_name` would render something like this

> Hi Philippe,

… and if it didn't match anything something like this:

> Hi there,

## Getting started

### Adding variables

Adding a variable to a response is as easy as clicking the **{{** icon in the response composer:

<div data-with-frame="true"><figure><img src="https://3242897856-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1If7JwIQhfz5wGM9LiIU%2Fuploads%2Fgit-blob-302b612ded681ae42b9a8cd81adfbf8e05e08d1f%2Ffeatures-add-variable-icone.png?alt=media" alt="Add a variable helper" width="135"><figcaption></figcaption></figure></div>

A new modal will open where you can easily create your variable without knowing the exact syntax.

<div data-with-frame="true"><figure><img src="https://3242897856-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1If7JwIQhfz5wGM9LiIU%2Fuploads%2Fgit-blob-d0baffc270244468cd5def12ba5340cb35efdd15%2Ffeatures-add-variable.png?alt=media" alt="Add a variable helper" width="563"><figcaption></figcaption></figure></div>

You can also create a response with dynamic content that entirely change depending if a variable is present or not.

It would look like this:

```liquid
{% if recipient.first_name == null %}Hello,
{% else %}Hi {{ recipient.first_name }},{% endif %}
```

... if there's no recipient first name, it will render like this:

> Hello,

... and if there's a recipient's first name, it will render like this:

> Hi Philippe,

### Build forms

When adding a variable, you don't have to use one that matches a data point provided by Missive ([recipient](#recipient-object), [user](#user-object)). You can create a variable linked to no data, like in this screenshot:

<div data-with-frame="true"><figure><img src="https://3242897856-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1If7JwIQhfz5wGM9LiIU%2Fuploads%2Fgit-blob-3ec5c40acc44231c3913f55d4724cd65a1f2fd56%2Ffeatures-description.png?alt=media" alt="Add a variable with no related data" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
Make sure to use **underscores** and **dots** instead of spaces.
{% endhint %}

When inserted in a draft, a form will ask the Missive user what should the value be:

Instead of using text placeholders (that you might forget to replace), this technique lets you create forms your team always has to fill in when inserting a response.

### Liquid.js

Our templating engine is based on [liquid.js](https://shopify.github.io/liquid/) and supports all of its [tags](https://shopify.github.io/liquid/tags/control-flow/) and [filters](https://shopify.github.io/liquid/filters). Make sure to read the documentation if you want to go deeper and create complex logic.

## Objects

### `recipient` **object**

The recipient data is matched by first looking into the user contacts for matches based on the message recipient address, then on the message data itself.

#### Labels

Contact labels can be used to scope the search. For instance `{{ recipient.work.phone_number }}` would search only in phone numbers with the label *work*.

| Object key                       | Description                                                                                                                                                                  | Example                                                                                            |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `recipient.handle`               | Handle of the recipient(s). This depends on the message type, can be an email address, a phone number, etc.                                                                  | <p><code><frodo@missiveapp.com></code><br><code>+1 (155) 555-555</code><br><code>@frodo</code></p> |
| `recipient.name`                 | First and last name(s) of your recipient(s).                                                                                                                                 | `Philippe Lehoux`                                                                                  |
| `recipient.first_name`           | First name(s) of your recipient(s).                                                                                                                                          | `Philippe`                                                                                         |
| `recipient.middle_name`          | Middle name(s) of your recipient(s).                                                                                                                                         | `L.`                                                                                               |
| `recipient.last_name`            | Last name(s) of your recipient(s).                                                                                                                                           | `Lehoux`                                                                                           |
| `recipient.email`                | Email address(es) of your recipient(s).                                                                                                                                      | `frodo@missiveapp.com`                                                                             |
| `recipient.phone_number`         | Phone number of your recipient(s).                                                                                                                                           | `+1 (155) 555-555`                                                                                 |
| `recipient.url`                  | URL(s) associated with your recipient(s).                                                                                                                                    | `https://missiveapp.com/`                                                                          |
| `recipient.physical_address`     | Physical address(es) associated with your recipient(s).                                                                                                                      | <p><code>123 Missive Street</code><br><code>Quebec, QC, G1K 3B4</code><br><code>Canada</code></p>  |
| `recipient.twitter`              | Twitter username(s) associated with your recipient(s).                                                                                                                       | `@frodo`                                                                                           |
| `recipient.facebook`             | Facebook username(s) associated with your recipient(s).                                                                                                                      | `Philippe Lehoux`                                                                                  |
| `recipient.nickname`             | Nickname of your recipient(s).                                                                                                                                               | `Chewbacca`                                                                                        |
| `recipient.prefix`               | Prefix(es) of your recipient(s).                                                                                                                                             | `Mr.`                                                                                              |
| `recipient.suffix`               | Suffix(es) of your recipient(s).                                                                                                                                             | `PhD`                                                                                              |
| `recipient.gender`               | Gender(s) of your recipient(s).                                                                                                                                              | `Male`                                                                                             |
| `recipient.file_as`              | File as value of your recipient(s).                                                                                                                                          | `ACME`                                                                                             |
| `recipient.phonetic_first_name`  | Phonetic first name(s) of your recipient(s).                                                                                                                                 |                                                                                                    |
| `recipient.phonetic_last_name`   | Phonetic last name(s) of your recipient(s).                                                                                                                                  |                                                                                                    |
| `recipient.phonetic_middle_name` | Phonetic middle name(s) of your recipient(s).                                                                                                                                |                                                                                                    |
| `recipient.custom.order_amount`  | Access your recipient(s) custom contact data. Both variations **Order Amount** and **order\_amount** would be accessible using the same key: `recipient.custom.order_amount` | `$99`                                                                                              |

### `user` **object**

The user object data is matched with the logged-in Missive user (you).

| Object key          | Description               | Example                |
| ------------------- | ------------------------- | ---------------------- |
| `user.first_name`   | First name of the user    | `Philippe`             |
| `user.last_name`    | Last name of the user     | `Lehoux`               |
| `user.name`         | Name of the user          | `Philippe Lehoux`      |
| `user.email`        | Email address of the user | `frodo@missiveapp.com` |
| `user.avatar_url`   | URL of the user avatar    | `https://...`          |
| `user.status`       | Status of the user        | `Working from home`    |
| `user.status_emoji` | Status emoji of the user  | 🏠                     |

### `conversation` **object**

The conversation object data is matched with the current conversation.

| Object key        | Description                | Example                                |
| ----------------- | -------------------------- | -------------------------------------- |
| `conversation.id` | The ID of the conversation | `d85eed67-5ac2-477b-aa27-521f01eb9783` |

### `message` **object**

The message object data is matched with the current draft.

| Object key                | Description                                                                                           | Example                                                                                            |
| ------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `message.id`              | The ID of the message                                                                                 | `d85eed67-5ac2-477b-aa27-521f01eb9783`                                                             |
| `message.from_handle`     | Handle of the sender. This depends on the message type, can be an email address, a phone number, etc. | <p><code><frodo@missiveapp.com></code><br><code>+1 (155) 555-555</code><br><code>@frodo</code></p> |
| `message.from_email`      | Email address of the sender                                                                           | `info@missiveapp.com`                                                                              |
| `message.from_name`       | Name of the sender                                                                                    | `Philippe Lehoux`                                                                                  |
| `message.from_first_name` | First name of the sender                                                                              | `Philippe`                                                                                         |
| `message.from_last_name`  | Last name of the sender                                                                               | `Lehoux`                                                                                           |
