Node.js – Express+jade: local variable not available in view

expressnode.jspug

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!

Best Answer

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

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