Express + jade:本地变量在视图中不可用 [英] Express+jade: local variable not available in view

查看:123
本文介绍了Express + jade:本地变量在视图中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常基本的问题,但似乎找不到答案。我正在使用 node.js express ,我只是想将一个局部变量传递给这个视图, :

  app.get('/',function(req,res){
res.render(index ,{localals:{
title:Blog,
}
});
});

我的索引视图同样简单:

  h1 = title 

但是由于某种原因,这个错误就好像局部变量永远不会传递:

  500 ReferenceError:/ home / spartan / Node_Projects / test / views / index .jade:1> 1 | h1 = title 2 |标题未定义
> 1 | h1 = title
2 |标题没有定义

我不知道我做错了什么!以下是我使用的版本:




  • Express:3.0.0alpha1

  • node.JS: 0.6.14

  • 玉:0.24.0



有人请帮忙,所以我可以移动要学习节点+ express!

解决方案

你应该传递没有 locals 。这在快速3.0.0中可能是新的。

  res.render(index,{title:Blog}); 


I ran into a very basic problem but I can't seem to find the answer to it. I am working with node.js, express and I am just trying to pass a local variable into the view like this:

 app.get('/', function(req, res){
  res.render("index", {locals: {
    title: "Blog",
    }
  });
});

My index view is equally simple:

h1= title

But for some reason, I keep getting this error as if the local variable is never passed:

 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

I don't know what I am doing wrong! Here are the versions I am using:

  • Express: 3.0.0alpha1
  • node.JS: 0.6.14
  • Jade: 0.24.0

Someone please help so I can actually move on to learning node + express!

解决方案

You should pass the variable without the locals. This is probably new in express 3.0.0

res.render("index", {title: "Blog"});

这篇关于Express + jade:本地变量在视图中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆