Variables and Default Values
A variable is a placeholder in template content that resolves to one contact's own data when the message is sent. Both channels work the same way, and both use the same Test Data and Defaults tab to preview that content and to decide what a contact sees when the data is missing.
Inserting a Variable
Insert Variable places a variable at the cursor position. The menu lists the contact fields available on a contact, grouped so reserved fields and custom fields are easy to tell apart.
Each field is listed under its raw name, which is not the label a contact page uses for it: the field shown there as Phone Number is offered here as phoneNumber. Reserved Fields gives both names for every reserved field, so the right one can be picked without guessing.
| Where | How to insert |
|---|---|
| SMS message | Insert Variable, beside the message field |
| Email body, design editor | Select a text based block, place the cursor, then use the variable inserter in the block properties |
| Email body, code editor | The variable button in the toolbar, which writes a variable tag into the HTML |
| Email subject line | The variable control on the subject field |
A variable appears as a tag while editing, in both the editor and the field it was inserted into. Email templates also offer an unsubscribe variable, which is not a contact field: it resolves to a unique opt out link for each recipient and is required before an email campaign can be finished.
A template built inside a campaign that sends to a file is the one exception. There the menu offers the columns mapped on the file rather than contact fields, because the file supplies the data. See Adding a Template.
Test Data
Test data is the set of sample values used to preview a template. It never reaches a real campaign.
- Open the Test Data and Defaults tab.
- Enter a sample value for a field, for example "Jane" for a first name.
- The preview redraws with that value in place of the tag.
Where no sample value is entered, the preview keeps showing the raw placeholder, which makes it obvious where a variable sits. Sample values are also used by Send Test SMS and Send Test Email, so a test message reads the way a real one will.
Test data belongs to whoever is working on the template at the time. A campaign that applies a saved template shows the content read only but leaves the test data fields editable, so a campaigner can preview with values that suit the campaign without altering the library.
In the subject line and in the code editor's HTML, a variable always stays a tag. Sample values resolve in the preview panel and in test messages only.
Default values
A default value is what a contact receives when that contact has no value for the field.
Resolution runs in a fixed order when a message is built:
- The contact's own value for the field.
- The default value set on the template, if the contact has no value.
- Blank, if no default value is set.
A field with no default and no value for that contact therefore resolves to an empty string. Nothing is skipped and no placeholder text is delivered, but the sentence around the variable is sent with a gap in it, which is why a default is worth setting on anything that reads badly when it is missing. "Hi there" as the default for a first name is safer than a sentence that opens with a blank.
Defaults are set per field on the Test Data and Defaults tab, alongside the sample value for that field.
Which Fields Appear on the Tab
The tab lists only the fields actually used in the template, so it grows and shrinks as content is written. Removing the last mention of a field from the content removes its row.
Values already typed for a field are held for the rest of the editing session. Remove a variable and add it back before closing the template and its sample value and default value are still there. Once the session ends, a field that is no longer in the content keeps nothing.
Finishing Without Defaults
SMS
Finishing an SMS template while one or more fields have no default value opens a Continue Without Default Values? prompt. It warns that recipients with no value for those fields will see a blank in the message, and offers:
- Cancel, to go back and set the missing defaults.
- Continue Anyway, to keep going with blanks.
Email
The email requirements modal lists default values alongside the other items it reviews before a campaign is finished, such as the sender addresses and the unsubscribe link. A field with no default value is flagged there and nothing more: it never blocks the save, and the template can be saved and the campaign finished with the default value still empty. Recipients with no value for that field receive a blank, as set out under Default values.
Invalid Default Values
A default value has to match the type of the field it belongs to. Custom fields are Text, Number or Date, so a Date field cannot take a default of "soon" and a Number field cannot take a default of "n/a".
Where a default no longer matches its field's type, the template cannot be saved and this message is shown:
The template contains one or more invalid default values. Update the template default values and try again.
Open the Test Data and Defaults tab, correct the values it flags, and save again.
A default value of the wrong type is the one default value problem that stops a save. A missing default value is only ever flagged.
Sending a Test Message
A test message uses the current content, the current sender settings and the current sample values.
- SMS: Send Test SMS sends to up to 10 numbers entered in the modal.
- Email: Send Test Email opens a modal showing the From, Reply-to and Subject in use and the current sample values, with a field for up to 10 addresses and a button that fills in the signed in user's own address.
Test messages are a preview tool. They are not counted against a campaign and do not create runs or messages. After changing a template it is worth sending another test, since the previous one no longer reflects the content.
Related Guidance
- Fields. The reserved and custom fields a variable can draw on
- SMS Templates. Writing SMS content and its character limits
- Email Templates. The email editor and its tabs
- Sender Settings. Using variables in the subject line