Categories
express node.js pug

express+jade: provided local variable is undefined in view (node.js + express + jade)

I’m implementing a webapp using node.js and express, using the jade template engine.

Templates render fine, and can access helpers and dynamic helpers, but not local variables other than the “body” local variable, which is provided by express and is available and defined in my layout.jade.

This is some of the code:

app.set ('view engine', 'jade');
app.get ("/test", function (req, res) {
res.render ('test', {
locals: { name: "jake" }
});
});

and this is test.jade:

p hello
=name

when I remove the second line (referencing name), the template renders correctly, showing the word “hello” in the web page. When I include the =name, it throws a ReferenceError:

500 ReferenceError: Jade:2 NaN. 'p hello' NaN. '=name' name is not defined
NaN. 'p hello'
NaN. '=name'

I believe I’m following the jade and express examples exactly with respect to local variables. Am I doing something wrong, or could this be a bug in express or jade?