yads / nodemailer-express-handlebars

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

The partial could not be found #27

Closed mirkadev closed 5 years ago

mirkadev commented 5 years ago

My viewEngine:

viewEngine: {
  partialsDir: resolve(__dirname, '..', 'views', 'mails', 'partials'),
  defaultLayout: resolve(
    __dirname,
    '..',
    'views',
    'mails',
    'layouts',
    'main.hbs',
  ),
},

Main.hbs works and tag {{{body}}} inside it too. But if I trying use {{> top }} in main.hbs file, I get error: The partial top could not be found

mahsan3-zz commented 5 years ago

I have the same issue, my config was

const handlebarOptions = {
  viewEngine: {
    partialsDir: path.join(__dirname, '/../templates/partials'),
    layoutsDir: path.join(__dirname, '/../templates'),
    defaultLayout: false
  },
  viewPath: path.join(__dirname, '/../templates'),
  extName: '.hbs'
};

Looks like the partials with the extension 'hbs' don't work, even though extName is set. When changing the extension to 'handlebars' for the partials, it works.

mirkadev commented 5 years ago

So, it work:

transporter.use(
  'compile',
  hbs({
    viewPath: resolve(MAIL.TEMPLATE_DIR),
    viewEngine: {
      partialsDir: resolve(MAIL.TEMPLATE_DIR, 'partials'),
      defaultLayout: resolve(MAIL.TEMPLATE_DIR, 'layouts', 'main.hbs'),
      extname: '.hbs',
    },
    extName: '.hbs',
  }),
);
mahsan3-zz commented 5 years ago

So yes it does, basically the difference being the key 'extName' within the viewEngine block is all lower case. Having both of these the same casing would be more consistent, and can prevent simple slip ups.