JakeM
JakeM

Reputation: 73

Can I assign to a jade variable from inside javascript?

I've seen tons of questions the other way around, but can't find one for assigning to.

So, why can I do this:

var username = '#{username}';

But not this?

#{username} = username;

Is there a way to assign to jade variables from inside javascript?

Edit: I ended up doing what Bigood suggested and using server and client side cookies, that works great! I followed a guide that I found from here https://stormpath.com/blog/everything-you-ever-wanted-to-know-about-node-dot-js-sessions/

Upvotes: 1

Views: 119

Answers (1)

Deendayal Garg
Deendayal Garg

Reputation: 5148

When you do #{username} = username inside Jade, The #{username} get replaced with the value of username.

for example, lets say you are passing username='Jake' to your jade template. so when you write

#{username}= "somethingElse"

It actually becomes

<Jake> = "somethingElse"</Jake>

Thats the reason we cant do that.

Upvotes: 1

Related Questions