javascript - How to use variables in Jade passed via res.render -


first of all, want apologyze english.

i have code on router file:

exports.index = function (req, res) {   res.render('./game/main', {name:req.session.name, menuop:'home'}); } 

and have .jade extends file.

[main.jade]

extends mainlayout  block topmenu     -var selected = '#{menuop}' 

but throws error. question is... why can print variable can't assign another? mean, following code works fine:

block topmenu     h1 #{menuop} 

but when try assign, doesn't work.

by way, tried , worked too:

block topmenu     -var selected = 'home' 

so think problem #{variable} works print or something.

it's not 100% clear you're trying do, think want this:

block topmenu     -var selected = '#' + menuop 

when use dash, jade interprets follows javascript, putting variable inside string isn't going expand variable. if literally want new variable puts hash in front of string, can use syntax above.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -