我正在尝试使用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}
------------^为什么会这样呢?
发布于 2018-01-13 22:02:50
您不需要引用isAnonymous,该行以"if“开头,因此它被视为javascript。
doctype html
html
head
if isAnonymous
title Test page
else
title #{name} - Test pagehttps://stackoverflow.com/questions/48244253
复制相似问题