在模板文字中设置 href

Setting a href inside of template literals

我正在尝试使用一个很好的电子邮件模板,当用户使用他们的电子邮件注册时,我正在使用 express & node mailer 来完成这个。以前我的代码看起来像:

"Hello, " +
 user.username +
 ",\n\n" +
"Please complete your registration by clicking the link:
 \nhttp://" + req.headers.host + "/confirmation/" + user.username + "/" + token.token +
"\n\nThank you!\n"

在我的 HTML 模板中,这是一个我试过的模板文字:

const output = ` <a href="${req.headers.host} + "/confirmation/" + ${user.username} + "/" + ${token.token}"  `

但这不起作用,电子邮件的 <a> 里面没有 href

我一定是遗漏了一些非常基本的东西...感谢您的观看 =)

使用 `` 不需要将字符串与 + 连接,因此它应该如下所示:

const output = `<a href="${req.headers.host}/confirmation/${user.username}/${token.token}"></a>`