node.jsemailtemplatespostmark

Postmark template: dynamic variable with html processed as text instead of html


I have a Postmark email template where the dynamic variable contains html. However, it processes that html as plain text.

More concretely, I have the code below. The variable body is sent to the email template, however the <br><br> is displayed as text instead of that it goes to the next line.

In controller:

const body = "Hi...<br><br> Welcome to our a new episode.";
client.sendEmailWithTemplate(
    {
        TemplateAlias: process.env.POSTMARK_TEMPLATE,
        TemplateModel: {
            body: body
        },
        From: from,
        To: email,
    });

In Postmark template:

<tr>
  <td>
    1. The following includes text with a br break: {{body}}
  </td>
</tr>
<tr>
  <td>
    2. This line includes a br break directly in the template: How are you? <br> Anything new?
  </td>
</tr>

This results in an email where the br break does work on location 2 but not on location 1. On location 1 <br> <br> is displayed as text: "<br> <br>".

What am I doing wrong?


Solution

  • Postmark support provided the answer:

    We normally escape HTML but you can get around that by using this syntax for the variable:

    {{{body}}} or {{&body}}

    The triple braces or ampersand will let you put HTML into that variable when populating your TemplateModel values.