Jean Michel Cordier
Jean Michel Cordier

Reputation: 11

jade extends layout and if statement

hi and sorry for my english.

I've a very simple "layout.jade"

!!! 5
html
    head
        title= title
        link(rel='stylesheet', href='/stylesheets/style.css')
    body
        block content

and a very simple "index.jade"

extends layout

block content
     - if (session) {
          p Welcome
     - } else {
          p Login
      -}

With this code i've got a blank page.

Now if i remove extends layout from my "index.jade" and i put the code directly in "index.jade" everything works fine, that is to say my conditional statement give me <p>Welcome</p> or <p>Login</p> no blank page any more.

I'm new to nodejs and my problem may be evident for many of you ;)

Thanks!

Upvotes: 1

Views: 1566

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146014

It looks like you have a leading whitespace mismatch, which is a no-no in significant whitespace languages like jade. Also if and else are directly supported in jade:

extends layout

block content
  if session
    p Welcome
  else
    p Login

Upvotes: 2

Related Questions