John Doe
John Doe

Reputation: 215

jade conditional unexpected token illegal

Im building a small application with express, node, and jade. I am trying to get this to work:

    if user
      p Welcome, #{user.fullName} 
      p
      .div(style={position: 'absolute', right: '150px', top: '75px'})
        unless #{user.email} == "[email protected]"
          a.btn.btn-primary(href="/upload") Upload New Schedule
          br
        br
        a.btn.btn-primary(href="/logout") Logout

I tried running the above and it is giving an error on the line:

        unless #{user.email} == "[email protected]"

Unexpected token ILLEGAL at Function ()

Any ideas on what is going on? Everything is indented by the way. Thanks!

Upvotes: 2

Views: 295

Answers (1)

Sascha
Sascha

Reputation: 1156

change

unless #{user.email} == "[email protected]"

to

unless user.email == "[email protected]"

run it

$ cat test.jade && jade test.jade && cat test.html
- var user={fullName:'me',email:'[email protected]'}
if user
  p Welcome, #{user.fullName} 
  p
  .div(style={position: 'absolute', right: '150px', top: '75px'})
    unless user.email == "[email protected]"
      a.btn.btn-primary(href="/upload") Upload New Schedule
      br
    br
    a.btn.btn-primary(href="/logout") Logout
  rendered test.html

<p>Welcome, me </p><p></p><div style="position:absolute;right:150px;top:75px" class="div"><a href="/upload" class="btn btn-primary">Upload New Schedule</a><br/><br/><a href="/logout" class="btn btn-primary">Logout</a></div>

You'll have to make sure that user is defined, otherwise the conditional part will be rendered always

Upvotes: 1

Related Questions