Jade dynamic data

Problem

Using node.js I am passing some variables to jade view:

res.render('index', {
        locals: { 
                      name: user.name, 
                      hashpassword: JSON.stringify(user.hashPass), 
                      languages: JSON.stringify(langs)}
                });

In jade file I have:

body
    #heading
      h1 nodechat
      label !{locals.languages} // working - printing whole json string
    #content
      - var laangs = !{locals.languages} //not working here!
                   //SyntaxError: Unexpected token .

      - each item in laangs
        label= item.EnglishName

The problem is that I cannot pass locals.languages to a variable in jade file. If I assign it to a single html element (like label), it's working, but when I try with var = that doesn't work.

What may be the problem?

Problem courtesy of: misaizdaleka

Solution

See my change below...

body
    #heading
      h1 nodechat
      label !{locals.languages} // working - printing whole json string
    #content
      //- Do it like this...You're already in JavaScript land after the -
      - var laangs = locals.languages
      - each item in laangs
        label= item.EnglishName

Change !{locals.languages} into locals.languages

Solution courtesy of: Split Your Infinity

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.