alexzaganelli/strapi-plugin-email-designer

error when sending the e-mail template if a variable is used in a "headline"-element

sandro-pagliara28 opened this issue · 4 comments

Bug report

Describe the bug

When sending the email programmatically, we pass a variable (e.g. service.title) . We use this in the e-mail template in a headline element. When triggering the email, we get the error (SERVICE is not defined).

Steps to reproduce the behavior

  1. Add any Variable programmatically.
  2. Open the E-Mail-Template, add a headline-Element and write the variable in it.
  3. See error when triggering the email.

Expected behavior

You should be able to use a variable in a headline element.

System

  • Node.js version: > v14.21.2
  • YARN version: v1.22.19
  • Strapi version: v4.5.6
  • Plugin version: 2.1.2

Thank you!! This is your first issue on this repo

I confirm there is a problem

5ika commented

Same problem. The variable name is uppercased (service => SERVICE) so it's not recognized during the variable replacement.

found a workaround

in your template write it as follows

{{= FIRSTNAME}}

then in your controller:

await strapi
        .plugin('email-designer')
        .service('email')
        .sendTemplatedEmail(
          {
            // required
            to: options.to,
          },
          {
            // required - Ref ID defined in the template designer (won't change on import)
            templateReferenceId: options.templateReferenceId,
          },
          options.parameters,
        );

where options looks like this:

{
    "to": "johndoe@gmail.com",
    "templateReferenceId": 1,
    "parameters":{
        "FIRSTNAME": "John Doe"
    }
}