ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Always use default template #258

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?

UziTech commented 5 years ago

layout and template are two different things. Think of the layout as the common parts of all of the templates. (header, footer, etc.)

express-handlebars renders the template then renders the layout.

In your case it is always rendering new_message_from_shooter.hbs (defaultLayout) last so that is what is rendered.