Templates
Template variables
Personalize a template with values supplied at send time.
Syntax
A variable is a name in triple braces, with an optional fallback after |:
Hi {{{NAME}}}
Hi {{{NAME|there}}}Variables work in the subject, the preview text, the HTML, and the plain-text part. Names can use letters, numbers, underscores and dots, and are case-sensitive. Double braces ({{NAME}}) are not variables.
In the visual editor, open the Variables menu to insert one. It lists Contact properties (contact.first_name with the fallback there, contact.last_name, contact.email, and each custom property) and System (OPENSEND_UNSUBSCRIBE_URL). Click an inserted variable to change its Variable and Fallback.
Values at send time
Pass values in template.variables when you send:
{"template":{"id":"welcome","variables":{"NAME":"Ada","total":42}},"to":"ada@example.net"}For each ordinary template variable, Opensend uses the value you pass, then the variable's fallback. An empty-string value counts as not passed. A variable with no value and no fallback makes the send fail with Missing template variables. Values are strings of up to 2000 characters or numbers. Values are HTML-escaped in the HTML part.
Contact variables (contact.*) and OPENSEND_UNSUBSCRIBE_URL are filled only by broadcasts and automation sends. A plain API send does not look up contact data or generate an unsubscribe link; unsupplied values use their fallback or an empty string.
Define variables through the API
The dashboard infers variables from the text. The templates API can also define them explicitly, with a type and a fallback:
{"variables":[{"key":"name","type":"string","fallback_value":"there"},{"key":"total","type":"number","fallback_value":0}]}- A template can use at most 50 variables.
- Keys start with a letter or underscore, contain letters, numbers and underscores, are unique, and are up to 50 characters.
- Types are
stringandnumber. A passed value must match the type, and a fallback is up to 2000 characters. FIRST_NAME,LAST_NAME,EMAIL,RESEND_UNSUBSCRIBE_URL,contact, andthisare reserved and cannot be defined.