Reputation: 9
I'm having big issues accessing a variable in my html code.
I have a simple function
module.exports =
{
sendEmail(from,to,subject,html)
{
return new Promise((resolve,reject) => {
transport.sendMail({from,subject,to,html}, (err,info) => {
if (err) reject(err);
resolve(info);
});
});
}
}
This works like a charm.
Then in my users.js I have
const thissecretToken = randomstring.generate();
const html = 'Hey!!, </br>, Thank you for registering </br> Tu token es: <b>
${thissecretToken} </b>' ;
When i recieve the email, it says literally "${thissecretToken}" And not the token variable.
What am i doing wrong?
Is handlebars changing anything?
EDIT : Solved. I was using ' instead of `
Upvotes: 0
Views: 297
Reputation: 2032
To include variables in a string you need to use different apostrophes. Like this:
const thisSecretToken = "4-8-15-16-23-42"
const html = `Thanks for registering.<br/>Tu token es <b>${thisSecretToken}</b>`;
console.log(html);
document.write(html);
Notably that uses `
and not '
.
Upvotes: 1