yads / nodemailer-express-handlebars

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

Always use default template #28

Closed mixalistzikas closed 5 years ago

mixalistzikas commented 5 years ago

I have the following settings with nodemailer

this.mailer.use('compile', hbs({
    viewEngine: {
        extname: '.hbs',
        layoutsDir: 'src/emails/',
        partialsDir: 'src/emails/',
        defaultLayout: 'new_message_from_shooter.hbs',
    },
    viewPath: 'src/emails/',
    extName: '.hbs'
}));

When I call this

this.mailer.sendMail({
            from: `info@photoshooter.gr>`,
            to: 'to@photoshooter.gr',
            subject: `Test message user`, // Subject line
            template: 'new_message_from_user',
            context: {
                a: 1
            }
        });

or this

this.mailer.sendMail({
            from: `info@photoshooter.gr>`,
            to: 'to@photoshooter.gr',
            subject: `Test message shooter`, // Subject line
            template: 'new_message_from_shooter',
            context: {
                a: 1
            }
        });

I always get the same template.... "new_message_from_shooter"

Any ideas?

colfax4 commented 5 years ago

In case others encounter this (as I did), here's what I did to get it to work:

transporter.use('compile', hbs({
  viewEngine: {
    extName: '.hbs',
    partialsDir: './helpers/templates/',
    // layoutsDir: './helpers/templates/',
    defaultLayout: false,
  },
  viewPath: './helpers/templates/',
  extName: '.hbs',
}));

The key here being the "defaultLayout: false". It's still unclear to me how one would actually utilize a defaultLayout while overriding it during "sendMail" since, as the issue description suggests, it appears to always use the defaultLayout when specified. Luckily, this is not my usecase. :smile: