rabidmachine9
rabidmachine9

Reputation: 7965

help with displaying a variable in jade express

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

Upvotes: 15

Views: 37386

Answers (3)

Scott Montreuil
Scott Montreuil

Reputation: 11

Here is what works for me.

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

in Jade
   #{locals.email}

Upvotes: 0

Jesús Carrera
Jesús Carrera

Reputation: 11425

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}

Upvotes: 7

James Andino
James Andino

Reputation: 25769

try

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

        #{locals.foo}

Upvotes: 21

Related Questions