【发布时间】:2018-06-22 23:28:18
【问题描述】:
我正在尝试使用 PugJS 创建一个简单的模板,但我无法从传递给渲染器的对象中读取数据。这就是我所拥有的:
// main.js -- nodejs + expressjs
const defaultUser = { isAnonymous: true, name: 'test' };
app.get('/', (req, res) => {
res.send(pug.compileFile(__dirname + '\\views\\index.pug', defaultUser));
});
// index.pug -- the template I'm having trouble with
doctype html
html
head
if #{isAnonymous}
title Test page
else
title #{name} - Test page
我在模板的第 4 行收到语法错误(意外字符“#”):
> 4| if #{isAnonymous}
------------^
这是为什么呢?
【问题讨论】:
标签: node.js express templates pug