When using dyamic templates and substitutions to set the e-mail subject, the character &
is escaped to &
which makes the subject of the e-mail not show company / product names correctly.
EX: The subject is of the message received is Thanks for buying at C&A
instead of the expected: Thanks for buying at C&A
.
Create a new dynamic template and set the subject to {{subject}}
Send the e-mail informing a subject containing the &
character:
const sgMail = require("@sendgrid/mail");
const templateId = "XXXXXXXX";
const apiKey = "XXXXXXXXXX";
sgMail.setApiKey(apiKey);
const msg = {
templateId,
to: "[email protected]",
from: "[email protected]",
dynamic_template_data: {
subject: "Escape & work"
}
};
sgMail.send(msg);
Escape & work
Hello @rafaelrpinto
Looks like what you need to do is use a triple bracket on your subject so that handlebars does not HTML encode the content. So instead of using {{subject}}
use {{{subject}}}
. We have an example of this in our docs here and is talked about in the handlebars documentation here under HTML Escaping.
@kylearoberts
Yep, that solves my problem.
Thanks for the quick response.
Rafael
@kylearoberts
Yep, that solves my problem.
Thanks for the quick response.
Rafael
Please show how your msg looks like (code example) after you added {{{}}} ?
@maxirby
The code is the same, what changed is the subject definition on the template where I set to: {{{subject}}}
instead of {{subject}}
Thanks
On Thu, Aug 29, 2019 at 12:11 PM Rafael Pinto notifications@github.com
wrote:
@maxirby https://github.com/maxirby
The code is the same, what changed is the subject definition on the
template where I set to: {{{subject}}} instead of {{subject}}—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-nodejs/issues/741?email_source=notifications&email_token=AAN3HIAAR4C4A7P5BMV46M3QG6OFDA5CNFSM4FVM6IJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5N7KTI#issuecomment-526120269,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAN3HICBW77KL3A637OMKTDQG6OFDANCNFSM4FVM6IJQ
.
Most helpful comment
Hello @rafaelrpinto
Looks like what you need to do is use a triple bracket on your subject so that handlebars does not HTML encode the content. So instead of using
{{subject}}
use{{{subject}}}
. We have an example of this in our docs here and is talked about in the handlebars documentation here under HTML Escaping.