15

I'm trying to load some variables with res render like that:

res.render('blog_edit', {title: 'edit your blog', posts: "something"}); 

though title loads fine post always appears as undefined... here are some of the ways I tried...

=posts #{posts} 

and as a javascript variable

script document.write(posts) 

none of them is working... can you please help? thanks in advance

1
  • 2
    #{posts} works under express 3.x Commented Aug 13, 2013 at 11:54

3 Answers 3

21

try

 res.render('blog_edit', {locals:{title: 'edit your blog', posts: "something"}}); #{locals.foo} 
Sign up to request clarification or add additional context in comments.

2 Comments

github.com/visionmedia/jade if you look under the section public api it tells you the ways you can pass in variables(not very clearly though) Using locals is probably the best way to do it.
If I had to pass the same thing to an ejs file it gives me "Uncaught SyntaxError: Unexpected identifier" error. Any idea why ?
7

I'm using the latest versions today ("express": "4.11.2", "jade": "1.9.2") and this is the syntax that works for me:

res.render('blog_edit', {title: 'edit your blog', posts: "something"}); 

In template:

#{locals.posts} 

or

#{posts} 

1 Comment

Express 4.13 jade 1.11 but both ways don't work for me.
0

Here is what works for me.

in JS res.render('index', {email: req.params.email}); in Jade #{locals.email} 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.