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 use context objects in hbs and iterations of array of objects #55

Open ajithv11 opened 2 years ago

ajithv11 commented 2 years ago

I need to iterate my orders in my .hbs template. My code is given below ` var nodemailer = require('nodemailer'); var mailerhbs = require('nodemailer-express-handlebars'); let transporter = nodemailer.createTransport({ host: CONSTANT.SMTPHOST, port: 587, secure: false, auth: { user: CONSTANT.SMTPUSER, pass: CONSTANT.SMTPPASSWORD, }, });

transporter.use('compile', mailerhbs({ viewEngine: { extname: '.hbs', partialsDir: templatePath, layoutsDir: templatePath+'/layouts', defaultLayout: 'blank', }, viewPath: templatePath, extName: '.hbs' }))

` The problem is that in the mail context I can add access strings only in the hbs template

mailData.context = { orderId : 'testid', // This works user : user // This is object accessing user._id not working in hbs file }; Error I got is given below Handlebars: Access has been denied to resolve the property "_id" because it is not an "own property" of its parent. You can add a runtime option to disable the check or this warning: See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details