尝试呈现 nunjucks 模板但收到 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);
}
不知道这里出了什么问题。
最佳答案
我遇到了同样的问题,我的解决方案是使用路径模块:
const njk = require('nunjucks');
return njk.render(path.resolve(__dirname, '../views/email/' + 'email' + '.html'), articles);
关于node.js - nunjucks:找不到模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39050788/