Email template variables not working

Is anyone else experiencing issues with email template form variables?

I’ve tried the following with the syntax from the documentation:

Subject:

Invoice {InvoiceNumber} from Foo Bar

Body:


Invoice {InvoiceNumber} for the amount of {TotalAmount} is now available.

You have {TotalAmount} outstanding to be paid by {DueDate}.

Feel free to contact me if you have any questions.

Below is the output when I test email an invoice to myself. Worth noting too, I don’t have any issues with the @@variables@@ for HTML sales invoice footer forms.

Anyone on the forum have email template variables / merge fields working using the syntax shown here (shown below)?

e.g.

{CustomerName} {InvoiceNumber} {TotalAmount} {DueDate}

They don’t work :frowning: . These do,

{{ reference }}
{{ recipient.code }}
{{ recipient.name}}
{{ recipient.email }}
{{ recipient.address }}
{{ business.name }}

If anyone knows another, please tell.

1 Like

That’s something! I can get the customer name with {{ recipient.name }}.. I’ve tried guessing others e.g. {{ invoice.number }}, {{ total.amount }}, {{ due.date }}, and they convert to blanks.. so it seems like there’s a partially implemented schema. Given PDF generation works, it wouldn’t be too difficult to get the merge fields working?

If the software were open source and the documentation were a wiki, users like me would gladly spend a bit of time to help in return for the free software @lubos

Liquid is being slowly phased out.

However, no alternative is being given for users to load dynamic content into emails.

I will place this in bugs

2 Likes

You can try this code,

{% capture issue_date %}{% for field in fields %}{% if field.label == "Invoice date" %}{{ field.text }}{% endif %}{% endfor %}{% endcapture %}
{% capture due_date %}{% for field in fields %}{% if field.label == "Due date" %}{{ field.text }}{% endif %}{% endfor %}{% endcapture %}
{% capture invoice_number %}{% for field in fields %}{% if field.label == "Invoice number" %}{{ field.text }}{% endif %}{% endfor %}{% endcapture %}

<table style="width: 100%; border-collapse: collapse;">
  <tr>
    <td style="padding: 5px; font-weight: bold;">Invoice date:</td>
    <td style="padding: 5px;">{{ issue_date }}</td>
  </tr>
  <tr>
    <td style="padding: 5px; font-weight: bold;">Due date:</td>
    <td style="padding: 5px;">{{ due_date }}</td>
  </tr>
  <tr>
    <td style="padding: 5px; font-weight: bold;">Invoice number:</td>
    <td style="padding: 5px;">{{ invoice_number }}</td>
  </tr>
</table>
1 Like

And this code for subject,

{% capture invoice_number %}{% for field in fields %}{% if field.label == "Invoice number" %}{{ field.text }}{% endif %}{% endfor %}{% endcapture %} Invoice number: {{ invoice_number }}

2 Likes

Thank you @Frankie . I’ve been trying to guess the total amount field e.g. {{ total_amount }}.. however I’ve found your’s shown are the only three available if I loop through the available fields

{% for field in fields %}
  {{ field.label }}: {{ field.text }}
{% endfor %}

will output, in my example

 Invoice date: 19/01/2026

 Due date: 18/02/2026

 Invoice number: 19

:confused: just need total amount due on top of this

I don’t think this is possible, only with a custom field on your invoice it is, but you have to type the amount by hand (not the most elegant way)

Got no idea if this will still work as the version of manager I’m using is old, but it may help

{% for total in table.totals %}{% if total.label == 'Total' %}{% capture invoice_total %}{{ total.text }}{% endcapture %}{% endif %}{% endfor %}
{% for field in fields %}{% if field.label == 'Invoice date' %}{% capture invoice_date %}{{ field.text }}{% endcapture %}{% endif %}{% endfor %}
{% for field in fields %}{% if field.label == 'Due date' %}{% capture due_date %}{{ field.text }}{% endcapture %}{% endif %}{% endfor %}
{% capture if_due_date %}{% if due_date == null %}.{% else %} due by {{ due_date }}.{% endif %}{% endcapture %}
{% for total in table.totals %}{% if total.label == 'Balance due' %}{% capture balance_due %}{{ total.text }}{% endcapture %}{% endif %}{% endfor %}
{% capture if_balance_due %}{% if balance_due == null %} {{invoice_total}} {% else %} {{ balance_due }} {% endif %}{% endcapture %}

<b>{{ recipient.name }},</b>
Please find attached your Invoice Number <b>{{ reference }}</b> dated <b>{{ invoice_date }}</b>
The Invoice amount is <b>{{ invoice_total }}</b>
Total balance due is <b>{{ if_balance_due }}</b>

Gives me, for example,
Recipient,
Please find attached your Invoice Number 2404874 dated 15/01/2026
The Invoice amount is $ 244.05
Total balance due is $ 244.05

1 Like

Thank you @VACUUMDOG … this works! With the help of ChatGPT I’m using ‘strip’ filters to make sure extra spaces aren’t added, shown below.

For anyone interested the code I’m using is as follows:

Subject

{% capture invoice_number %}{% for field in fields %}{% if field.label == "Invoice number" %}{{ field.text }}{% endif %}{% endfor %}{% endcapture %} Invoice {{ invoice_number }} from BUSINESS NAME

Body

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

{% capture invoice_number %}
  {% for field in fields %}
    {% if field.label == "Invoice number" %}
      {{ field.text | strip }}
    {% endif %}
  {% endfor %}
{% endcapture %}

{% capture due_date %}
  {% for field in fields %}
    {% if field.label == "Due date" %}
      {{ field.text | strip }}
    {% endif %}
  {% endfor %}
{% endcapture %}

{% for total in table.totals %}
  {% if total.label == 'Balance due' %}
    {% capture balance_due %}{{ total.text | strip }}{% endcapture %}
  {% endif %}
{% endfor %}

{% capture if_balance_due %}
  {% if balance_due == blank %}
    {{ invoice_total | strip }}
  {% else %}
    {{ balance_due | strip }}
  {% endif %}
{% endcapture %}

Dear {{ recipient.name | strip }},

Please find attached Invoice {{ invoice_number | strip }} for the amount of {{ invoice_total | strip }}.

The outstanding balance of {{ if_balance_due | strip }} is due for payment by {{ due_date | strip }}.

If you have any questions or require further information, please don’t hesitate to contact me.

BUSINESS EMAIL SIGNATURE

Which will output

1 Like

I’ve been struggling with the spacing on my email templates for a while and using capture like this solves it perfectly.

@All I’ve got the same problems. I was using Liquid but out of the sudden my code isn’t working anymore.

Please see me post: Email and Datafields - #18 by canefield

Hopefully someone can help me out. I haven’t got any helpful answers yet.

Thanks in advance,

Canefield

I’m by no means an expert, so I will suggest using or modifying the code in my post above. I’m currently using this when I issue invoices, it does everything I need it to: client name, invoice number, total, remaining balance and due date.