Request to add variables into email body

In the latest version (17.3.9) you can use in email templates the same variables which are available in themes.

For example, to set up email template for sending invoices, you can put to subject line:

Invoice {{ reference }}

and to body:

{% for total in table.totals %}
  {% if total.label == "Total" %}
    {% capture invoice_total %}{{ total.text }}{% endcapture %}
  {% endif %}
{% endfor %}

Dear {{ recipient.name }},

Please see attached invoice {{ reference }}. Invoice total is: {{ invoice_total }}

I think subject line is obvious. The body looks a bit convoluted but that’s because I’m trying to demonstrate how to extract “Invoice total” from the list of totals. The first 5 lines basically loop through all totals, find the total with label “Total” and capture it to new “invoice_total” variable.

Of course, you can go totally crazy with {% if %} tags to generate completely different email based on conditions.

Just like themes, email templates are based on Liquid markup.

3 Likes