Template language
Templates are more than placeholders. Everywhere Variables are accepted - template content in HTML and text, subjects, header values, autoreply texts, attachment paths and executable arguments - you can also use conditions, comparisons and loops. The syntax uses the same single braces as variables.
The template preview on the Templates page renders the same syntax against sample data, so what you see in the designer is what will be sent.
Conditions
A block wrapped in {#if name} ... {/if} is rendered only when the variable is set and not
empty. The whole block is cut otherwise, separators included:
{firstName} {lastName}{#if mobileNumber} | M: {mobileNumber}{/if}
{else} renders the alternative branch:
{#if company}{company}{else}MSH Software{/if}
{else if ...} chains conditions. The first branch whose condition holds is rendered:
{#if and mail mobileNumber}
E: {mail} | M: {mobileNumber}
{else if mail}
E: {mail}
{else if mobileNumber}
M: {mobileNumber}
{/if}
What counts as set
A variable is treated as set when it resolves to a non-empty value. A missing attribute, an
unknown variable name and an empty value all count as not set. Any other text counts as set,
including 0.
Logic operators
Conditions combine variables with and, or and not, written without parentheses. and and
or take any number of operands, not takes one:
{#if and mail mobileNumber}both present{/if}
{#if or phoneNumber mobileNumber}some number exists{/if}
{#if not company}no company set{/if}
{#if and displayName jobTitle company}complete header{/if}
{else if} accepts the same operators, for example {else if or mail mobileNumber}.
Conditions take plain variable names such as mobileNumber or company. Variables with a
modifier after a colon, such as {message:subject} or {photo:100}, cannot be used inside a
condition.
Comparisons
The operators eq, neq, lt, lte, gt and gte compare two operands as a block with an
optional {else} branch:
| Operator | Meaning |
|---|---|
eq | equal |
neq | not equal |
lt | less than |
lte | less than or equal |
gt | greater than |
gte | greater than or equal |
Each operand is a variable name, a double-quoted string or a number:
{#eq department "Research"}R&D team{else}Business team{/eq}
{#eq country "Poland"}Pozdrawiam{else}Best regards{/eq}
When both operands are numbers the comparison is numeric, so 9 sorts before 10. Otherwise the
operands are compared as text. Quoted strings may contain spaces.
Loops
{#each list} ... {/each} repeats its content for every item of a message collection. Inside
the block, the fields of the current item are available as variables. {else} renders when the
collection is empty:
{#each message:attachments}
{fileName} ({size} bytes, {contentType})
{else}
no attachments
{/each}
{#each message:headers}{name}: {value}
{/each}
Recipients: {#each message:recipients}{email} ({type}); {/each}
| Collection | Item fields |
|---|---|
message:attachments | {fileName}, {size} in bytes, {contentType}, {type} |
message:headers | {name}, {value} |
message:recipients | {email}, {type} - TO, CC or BCC |
message:envelope:recipients is accepted as another name for message:recipients.
Inside a loop, other variables keep working - {message:subject} or {displayName} resolve as
usual. When an item field has the same name as a variable, the item field wins. A collection
name that is not in the table iterates nothing and renders the {else} branch.
Writing the blocks
- Type the blocks directly into the template - in the HTML source or the text version in the designer, or into a subject or header field. The Insert attribute menu of the designer inserts variables only.
- Block tags placed on lines of their own leave no empty lines behind; the renderer removes them.
- Every well-formed
{word}is read as a variable. A word in braces that is not a variable renders as nothing, so text that needs literal braces should not be written as{word}. Unmatched braces, such as a single{or}, are kept as they are. - A template that cannot be parsed - for example an
{else}outside of a block - is kept unchanged, so a syntax error never breaks message processing. Check the preview when a block does not render the way you expect.