yads / nodemailer-express-handlebars

A plugin for nodemailer that uses express-handlebars view engine to generate emails
87 stars 30 forks source link

how to create helper function #29

Closed sudoStatus200 closed 5 years ago

sudoStatus200 commented 5 years ago

I want to create a helper function for equality check. I tried like this:

transporter.use('compile', hbs({ viewEngine: { extName: ".handlebars", partialsDir: path.resolve(__dirname, "views"), defaultLayout: false // <----- added this }, viewPath: path.resolve(__dirname, "views"), extName: ".handlebars", helpers: { if_eql: function(a, b, opts) { if (a == b) { return true } else { return opts.inverse(this) } } } })); and `{{#if_eql this 'prime'}} ....

{{/if_eql}}`

but it gives error : message: 'Missing helper: "if_eql"',

sudoStatus200 commented 5 years ago

ok fixed it. it was a small mistake. correct ; ` transporter.use('compile', hbs({ viewEngine: { extName: ".handlebars", partialsDir: path.resolve(__dirname, "views"), defaultLayout: false, helpers: { if_eql: function(a, b, opts) { if (a == b) { return opts.fn(this) } else { return opts.inverse(this) } } }, }, viewPath: path.resolve(__dirname, "views"), extName: ".handlebars" }));

`