html - URLs with handlebars JS -
i'm trying use handlebars render url inside email html template sent user after registration confirmation step.
the link assembled follows:
var data = { user: { email: body.email, token: 'tmptoken', link: '/confirm?email=' + body.email + '&token=' + 'tmptoken' }, appname: 'xyz' };
the link used in following format:
"/confirm?email=x&token=y"
each time email sent, link tampered , becomes:
"confirm/?email=y&token=y"
, pretty annoying.
i'm using handlebars in nodejs refer url inside html using handlebars
<a href="{{{link_to}}}" style="border: 0;" target="_blank">
.
i tried using handlebars helpers:
handlebars.registerhelper('link_to', function() { return new handlebars.safestring(handlebars.utils.escapeexpression(data.user.link)); });
any thoughts why question marks in string converted "/?" ?
this code, based closely on code present, not inject /
. there's else going on somewhere. works expected:
var handlebars = require('handlebars'); var source = '<a href="{{{link_to}}}" style="border: 0;" target="_blank">'; var template = handlebars.compile(source); var data = { user: { email: 'foo@example.com', token: 'tmptoken', link: '/confirm?email=' + 'foo@example.com' + '&token=' + 'tmptoken' }, appname: 'xyz' }; handlebars.registerhelper('link_to', function() { return new handlebars.safestring(handlebars.utils.escapeexpression(data.user.link)); }); var result = template(data); console.log(result); // logs: <a href="/confirm?email=foo@example.com&token=tmptoken" style="border: 0;" target="_blank">
Comments
Post a Comment