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

Variable names are limited to alphanumeric characters, periods (.), underscores (_), and hyphens (-).

  • 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.

  • 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.

  • 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

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

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

  • 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

  • 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

  • Or you can go to Contact in the dropdown

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

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

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

  • 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

  • You can also select Contact from the dropdown

  • Select the contact attribute to map the variable with

  • Once the variable value is selected, you need to provide. default when it is empty

  • 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

  • Select the event property from the dropdown like Checkout URL.

  • You can also directly type the event property format in place of selecting from the dropdown e.g. {{event.properties.checkout_url}}

  • Once the variable value is selected, you need to provide. default when it is empty

  • 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

  • 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

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

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

Last updated

Was this helpful?