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

1

6

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?

Fasto answered 28/11, 2020 at 21:4 Comment(0)
F
14

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.

Fasto answered 30/11, 2020 at 12:22 Comment(1)
Do you know if we can use our own HTML code in direct value of key "TextBody"?Photosynthesis

© 2022 - 2024 — McMap. All rights reserved.