Request to add variables into email body

TL;DR: Please add the ability to use variables, specifically total and reference to the email templating system.

After having this issue: PDF creation fails when adding dynamic-web loaded elements

I sat and thought about it a little.

Whilst the adding of a dynamic image to the invoice is important, and I think still needs a fix, the URL’s that the user can click, should maybe be in the email body.

i.e. If I can use the variables in the Email body, I can generate all the links and things I need there, instead of in the PDF.

This also enables the user to construct an email like so:

Hey Customer!

For your recent purchase: {{reference}} you owe: {{total}}

Please use the below links to pay.

<snapscan link in HTML>
<payfast link in HTML>
<Anything else you want in HTML>   

Also, your full invoice is attached.

Sincererly,
Seller

What you think @lubos?

5 Likes

I think you ask for features that would bloat the software. Many users choose it specifically because it is leaner and simpler than the alternatives, yet still quite flexible.

This could be a great thing under email templates if we could bulk email customer accounts / invoices.

1 Like

Well, in the context of invoices, invoice total or balance due variables are within {{ table.totals }} variable which is an array.

So to extract total, you’d have to loop through this array variable to find the one you are after and save it manually into {{ total }} variable or similar.

One way to make this easier would be to support synntax like {{ table.totals['Balance due'].text }}

This would give you whatever text is under label Balance due. It’s not as pretty as {{ total }} but it’s more generic and future-proof.

1 Like

I agree, that would be great. The thing I’m pointing out though, is that currently, the email templates do not support the variables.

i.e. in the message body, if one inserts a variable {{ reference }}, it is not replaced when the email is sent.

e.g.

Notice how the ref is replaced in the subject but not the body.

The ability to access the variables more easily would be great too.

  1. Edit
    Just want to clarify, if I now send the email, it is received as seen here. I.e. with {{reference}} instead of the actual reference number.

I’m not sure how you see this creating bloat. This will only allow features that already exist to be accessed in more places, for those that want it. I.e. it will increase flexibility, WITHOUT the addition of buttons/steps/anything-bloatish.

Every feature requires code, @procsum. Even simple ones. And whenever you start adding features that interact with other features and modules, you make it more burdensome to make changes, because you have to run down all the possible interactions. I think that’s what @lubos meant when he said “future-proof.”

Yes, I’d agree, in general. Yet, it seems like this is less like a feature request, and more like a bug, if @lubos reply is anything to go by. It seems like a useful one, too, by the fact that a few people have liked it. I don’t agree with your assessment of things here at all. :confused: But okay.

Manager is great. It’s grow amazingly over the long while I’ve been here. So big ups to you @lubos and whatever team you work with.

The plan is that the same variables used in themes will be accessible by email templates. I will be looking at this later next month.

1 Like

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

Lubos, That’s awesome. Thank you so very much! I’ll post back (at some point) a picture of what can now be done with email. This is PERFECT for digital invoices.

1 Like

After fiddling around with the code, if language setting is different from English, the red “Total” can be translated and then the invoice_total works in the email text for other languages. If more than one language is used simultaneously then add “or”:

{% if total.label == “Total” or “(total in local language)” %

A great feature request by a user that was met by the developer. That’s what user ideas should be about, improving the software for everyone, even if not supported by the mods.

1 Like

Took me a while to get back to this:-P Mod are people too:-D

1 Like

Yes you are correct.