【发布时间】:2018-02-16 00:44:52
【问题描述】:
节点版本:v8.9.0;
我使用 mustache 从模板中渲染一些 html,如下所示:
static createHtml(title, variables, template) {
let header = fs.readFileSync(headerPath);
let content = fs.readFileSync(contentPath);
let footer = fs.readFileSync(footerPath);
var headerVars = {
title: title
};
console.log('createHtml: ', variables); // <- variables are as expected
try {
header = Mustache.render(header.toString(), headerVars);
content = Mustache.render(content.toString(), variables);
} catch (e) {
console.log('Moustache error:\n', e); // <- no error is thrown
}
const html = header + content + footer;
console.log('content', content); // <- content does not include filled variables when deployed
return html;
}
当我在本地机器上运行它时,一切正常,但是当它被部署时,变量并没有注入到模板中。我有几个假设,并试图找出环境与本地环境不同的所有可能方式,但到目前为止没有任何效果。它在 EC2 上部署到 AMI Linux 实例。
任何想法,我怎么能弄清楚有什么区别?根据控制台日志,它一定是 Mustache.render() 中的东西。
【问题讨论】:
标签: node.js templates mustache