Use the filters in this guide to explicitly control and set what rendered variable content will be.
Dyspatch does not do any escaping by default in the email builder. Using the escape
or noescape
filters, you can control what the rendered output will be for dynamic variables. You can append either filter to the end of a variable in the Email Builder, Subject Line, Preheader, or within a Block.
To explicitly set no escaping for a variable:
@{variable|noescape}
To escape content for a variable:
@{variable|escape}
On export, if the language or platform you're working with supports either the escape
or noescape
options, Dyspatch will automatically wrap your variable with the supported equivalent.
Here is the complete list of supported integrations using the filters and their expected output:
NoEscape
Templating Language | Export |
---|---|
Django | {{variable|safe}} |
Freemarker | ${variable?no_esc} |
Handlebars | {{{variable}}} |
Iterable | {{{variable}}} |
Jinja | {{variable|safe}} |
Mandrill | {{{variable}}} |
Pardot | {{{variable}}} |
Sendgrid | {{{variable}}} |
Escape
Templating Language | Export |
---|---|
Django | {{variable|escape}} |
Freemarker | ${variable?esc} |
Jinja | {{variable|escape}} |
Liquid | {{variable|escape}} |
Marketo | allowHTML="true" is added to the header tag* |
Responsys | ${variable?html} |
*Marketo does not support single variable escaping or unescaping. If you include a single escape to a variable, this will set the entire email to be escaped.
Email Builder Preview
The escape
filter will escape the value of the variable and display the raw content.
The noescape
will have no effect on the email builder preview, since we do not do any escaping by default.
The raw
filter can be used as a passthrough to push through any filters or functions that are supported by your rendering system.
To use the raw
filter, specify your variable and append the raw filter at the end with the passthrough logic inside the quotes. For example:
@{variable|raw("passthrough function in here")}
Here is an example DML input and expected output per language:
Language | DML Input | Output |
---|---|---|
Django | @{var|raw("func1:val|func2")} | {{var|func1:val|func2}} |
Freemarker | @{var|raw("func1(val)?func2")} | ${var?func1(val)?func2} |
Jinja | @{var|raw("func1(val)|func2")} | {{var|func1(val)|func2}} |
Liquid | @{var|raw("func1:val|func2")} | {{var|func1:val|func2}} |
Responsys | @{var|raw("func1(val)?func2")} | ${var?func1(val)?func2} |
AMPscript | @{var|raw("func1(func2(var))")} | %%=func1(func2(var))}} |
Iterable | @{var|raw("func1(func2 var)")} | {{func1(func2 var)}} |
Mandrill | @{var|raw("func var")} | {{func1 var}} |
The default
filter can be used to provide fallback for a dynamic variable in the instance that variable is not present in the data.
To use the default
filter, specify your variable and append the default value within the parentheses at the end. For example:
@{variable|default(fallback string)}
Here is the expected output per language for DML input of @{var|default(fallback string)}
:
Language | Output |
---|---|
Django | {{var|default_if_none:"fallback string"}} |
Handlebars | {{#if var}}{{var}}{{else}}fallback string{{/if}} |
Jinja | {{var|default("fallback string")}} |
Liquid | {{var|default:"fallback string"}} |
Marketo | ${var|'fallback string'} |
AMPscript | %%[ IF Empty(@var) OR @var == "Unknown" THEN set @var = "fallback string" ENDIF ]%% %%var%% |
Iterable | {{defaultIfEmpty var "fallback string"}} |
Mandrill | {{#if var}}{{var}}{{else}}fallback string{{/if}} |
Responsys | ${var!"fallback string"} |