nunjucks: Template not found

Sayem picture Sayem · Aug 20, 2016 · Viewed 10.1k times · Source

Trying to render a nunjucks template but getting Error: template not found: email.html.

server/
  views/
     email/
       email.html
  workers/
      email.worker.js
//email.worker.js
function createMessage(articles) {
   console.log(__dirname) // /<path>/server/workers

   nunjucks.configure('../views/email/');
   return nunjucks.render('email.html', articles);
}

No idea what's wrong here.

Answer

Hector Matias Gonzalez picture Hector Matias Gonzalez · Jan 25, 2017

I had the same issue my solution was using path module:

const njk = require('nunjucks');

return njk.render(path.resolve(__dirname, '../views/email/' + 'email' + '.html'), articles);