Using Filters in E-mail Templates

In addition to conditions (such as if/else), you can also use "filters" in e-mail templates. Filters modify the variables/placeholders before they are placed in the email, for example, converting a name to UPPERCASE.

Using Filters

You use variables/placeholders in the templates with double curly braces, like this:

{{ delivery_address.name }}

You add filters by placing a pipe after the variable and then the name of your filter. For example, in this case, the filter "upper":

{{ delivery_address.name | upper }}

This will convert the name "Amy Jacobs" to "AMY JACOBS".

Filter: upper

This filter converts the text you pass into uppercase letters:

{{ delivery_address.name | upper }}

This converts "Amy Jacobs" to "AMY JACOBS".

Filter: lower

This filter converts the text you pass into lowercase letters:

{{ delivery_address.name | lower }}

This converts "Amy Jacobs" to "amy jacobs".

Filter: length

This filter counts the number of characters in the text you pass:

{{ delivery_address.name | length }}

This converts "Amy Jacobs" to "10".

Example

You can use this to display text if a variable is filled in. If it is filled, its length will be greater than 0.

{% if shipment.trackingcode | length > 0 %}
Your order has been shipped with tracking code {{ shipment.trackingcode }}.
{% endif %}

Filter: url_escape

This filter modifies the text so that it can be used in URLs:

{{ email | url_escape }}

This converts "amy@example.org" to "amy%40example.org".

Example

You can use this to build a URL with variables from the order, while keeping the link clickable.

https://www.example.org/status?orderid={{ order.webshop_id | url_encode }}&email={{ emailaddress | url_encode }}

Did you find an answer to your question?