The template:
p= user
Outputs:
<p>{ admin: "true", human: "Foo Bar" }</p>
(among some other stuff that usually isn't seen by the the user but is used to render different parts of the layout (or not) depending on various factors)
The template:
p= user.human
Outputs:
<p>Foo Bar</p>
As expected so far. However, the template:
p= user.admin
Outputs:
<p></p>
I have no idea how this is even possible. The property is there when I output the entire object, but it disappears when I try to output just that property.
I've also tried using user['admin'] instead of user.admin, but that doesn't work either.
First question: how is this happening? Second question: how do I fix it?
Update 1: The pattern p #{user.admin} has the same effect, and p= user.admin.toString() results in a 500 error claiming 'user.admin' is not defined. Furthermore, JSON.stringify(user.admin) also results in the empty p tag (as in p= user.admin and p #{user.admin})
Update 2: p= JSON.stringify(user) does output the 'admin' property: {"admin":"true","human":"Foo Bar"} but iterating over user with each value,key in user does not output the 'admin' property. The output is extremely long in that case as it includes a bunch of functions and other things, but I used ctrl+f to search through the output and could not find 'admin'.
This might be because the value for admin is interpreted as a boolean. Some things to try:
p #{user.admin}
or
p= user.admin.toString()
Please try the following
each value, key in user
p #{value} [#{key}]
Does "admin" get outputed?
OK, here's what was wrong:
I was retrieving a Mongoose object that had the 'admin' property set, but the Schema didn't actually specify the 'admin' property at all. I'm unsure exactly how Jade was picking it up, but Mongoose was obviously highly confused about what the 'admin' property was and what to do with it.
The solution was to simply add 'admin': 'string' to my mongoose.Schema object.
Thanks to dave and King Julian for both of your help. I've upvoted your two answers since they did help me reach this conclusion (as well as your comments, but you don't get rep for those I'm afraid!).