express+jade: provided local variable is undefined in view (node.js + express + jade)
        Posted  
        
            by 
                Jake
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jake
        
        
        
        Published on 2011-01-06T02:49:15Z
        Indexed on 
            2011/01/06
            2:53 UTC
        
        
        Read the original article
        Hit count: 515
        
Hello. 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?
© Stack Overflow or respective owner