我遇到了一个非常基本的问题,但似乎找不到答案。我正在使用node.js
,express
,并且我只是试图将局部变量传递给 View ,如下所示:
app.get('/', function(req, res){
res.render("index", {locals: {
title: "Blog",
}
});
});
我的索引 View 同样简单:
h1= title
但是由于某种原因,我总是收到此错误,好像从未传递过本地变量一样:
500 ReferenceError: /home/spartan/Node_Projects/test/views/index.jade:1 > 1| h1= title 2| title is not defined
> 1| h1= title
2| title is not defined
我不知道我在做什么错!这是我使用的版本:
有人请帮忙,这样我实际上可以继续学习node + express!
最佳答案
您应该传递不带locals
的变量。这可能是Express 3.0.0中的新功能
res.render("index", {title: "Blog"});
关于node.js - Express + Jade : local variable not available in view,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10199400/