Skip to main content

Using Variables to Insert Data Into a Notification

How to personalize the content of your Notifications with variables and user profile data.

Data Sources for Substitution Variables

Courier allows you to use variables to insert values from two sources into your Notifications.

The Data Object

An object included in the send command to provide any data you want to pass into a message template via variables.

The data property

Courier will automatically reference the data path by default. You do not need to include it in your variable path if the key-value is at the top level of the data tree. Nested values will need to begin the path where the data value originates. {first_layer.second_layer}

The User Profile

  • Profile data can be provided in the profile object of the Send API request.
  • The User Profile associated with the recipient ID created via the Profiles API.
Note

If there is a conflict, data in the profile object of the Send API call wins over the value in the data object.

Read More: JSON Paths and Variables Basics

Using Variables in Notifications

Variables can be used to insert data throughout the content of your Courier notifications.

variable case type

Please note that variables should be in either camel case or snake case when mapping them to your data. Using dashes will result in a rendering [error].

  • All Notification types
  • Content Blocks (Text, Action, Markdown, Quote, Template, List)
  • Handlebars code (Template blocks / Email templates / Brands)
  • Email subject line and email addresses (From, To, CC, BCC)
Variable Placeholders
Rendered Preview With Variables

Inserting Data Values Into Content Blocks

To insert values from the data object, simply encase the variable name inside of single curly brackets: {variable_name}. Correctly formatted variables inside of Text, Markdown, Quote and List Blocks will be highlighted in green.

Text Block With Variables

Inserting Profile Values Into Content Blocks

To insert values from the profile object or data from the User profile created with the Profiles API, you will need to use a full JSONPath expression such as profile.variable. For example, if you wanted to insert the user's first name into an Action Block, you could use the expression profile.name.first.

Action Button with Variables
Variable Expression in Action Modal
Note

Variables used in the Action Block and Hyperlink URL modals will not be highlighted in green but are still valid.

Inserting Variables Into Handlebars

To insert data into Handlebars, use double curly brackets {{ }} around the variable using the same paths as you would in Content Blocks, however you need to include the Handlebars variable helper: To insert a variable from your JSON event, you need the variable handlebars helper: var

  • Data object: {{var "variable_name"}}
  • Profile data: {{var "profile.variable_name"}}

You will see Handlebars code in the Template Content Block type, Brand Templates, and the Handlebars override within Email Notifications.

Template Block With Variables
Handlebars Toggle

Inserting Variables Into Email Fields

In addition to the Handlebars Template override, variables are supported in the Subject line, From address, Reply-To, CC, and BCC in the email channel settings.

Email Subject With Variables
Email Channel Settings
Was this helpful?