节点JS将variables传递给Jade / Pug

出于某种原因,我不能通过节点JS传递一个variables到帕格模板。

app.get("/", function (req, res) { res.render('index', { hello : 'Hey'} ) }) 

….

 extends layout.pug block content h1 #{hello} guy 

这只是返回index.html文件中的“家伙”

我认为你正在使用JADE编码(#{你好})与“帕格”(更新翡翠)插件静态.html – 完全错误。

遵循以下几行:

  1. 先使用这个

     app.set('views', __dirname + '/public/views'); app.set('view engine', 'pug'); 
  2. 比通过这个第一次访问

     app.get('/', function (req, res) { res.render('index', { title: 'Hey', message: 'Hello there!'}); }); 
  3. 比“/ public / views”中的模板文件“index.pug”

     html head title= title body h1= message