Reputation: 189
I've a field will
in a collection, where user can save html text (through a WYSIWYG editor): it works fine and users can write/save some strings like this it's<strong>bold</strong> and sometimes <i>italic</i>.
Nothing crazy..
When a user send this field will
by email (as part of emailData
), rendered with meteorhacks:ssr
in an html template, the field show up as it's<strong>bold</strong> and sometimes <i>italic</i>.
with HTML tags as normal text.
So, anyone know the trick to render in the html email's body: 'it's bold and sometimes italic.'? Thanks.
My code is very complicated, lot of const
and succession of functions, but except of html rendering, it works fine and is finally structured like this:
SSR.compileTemplate('htmlEmail', Assets.getText('replycontact.html'));
var emailData = {
message: `${message}`,
will: `${will}`,
origincontactdate: `${origincontactdate}`,
contactname: `${contactname}`,
};
//send the mail
Email.send({
to: to,
from: from,
subject: subject,
html: SSR.render('htmlEmail', emailData),
});
Upvotes: 0
Views: 594
Reputation: 189
The problem was that Meteor was escaping the HTML string.
Therefore, the solution is to use 3 brackets {{{ }}}
instead of 2 - here for the emailData
in the html template : instead of {{will}}
, use {{{will}}}
.
The code above in the question remain as it.
source: https://stackoverflow.com/a/16565529/7281870
Upvotes: 1
Reputation: 7777
Your data is most likely being saved as HTML encoded in the database, eg
<b>
is saved as
<b>
If so, you simply need to unencode it using the Javascript decodeURI() function, which you can read more about here:
http://www.w3schools.com/jsref/jsref_decodeuri.asp
So your code will look like this:
var emailData = {
message: `${message}`,
will: decodeURI(${will}),
origincontactdate: `${origincontactdate}`,
contactname: `${contactname}`,
};
//send the mail
Email.send({
to: to,
from: from,
subject: subject,
html: SSR.render('htmlEmail', emailData),
});
Upvotes: 0