1

I have tried this in a couple different projects with same result. This is a node app with express 2.5.8 and jade 0.20.3 (but updating to newer version of jade and express dont change the problem below).

I have a simple jade layout:

"layout.jade"

doctype 5
html
  head
    title MongoDB example
  body
    h1 My first MongoDB app
    hr
    block body

Then an index content page that should inherit the layout and show the content:

"index.jade"

extends layout
block body
if (authenticated)
  p Welcome back, #{me.first}
  a(href="/logout") Logout
else
  p Welcome new visitor!
  ul
    li: a(href="/login") Login
    li: a(href="/signup") Signup

In server.js I have (pertaining to jade):

app.set('view options', { layout: false });

But when I run the server and load the page I only get the content on the layout and not the index page. If I remove 'extends layout' then I get the content from the index page but not the layout. So, the output I get is:

<html>
  <head><title>MongoDB example</title></head>
  <body>
    <h1>My first MongoDB app</h1><hr>
  </body>
</html>

Figure this must be something simple I have overlooked but no love on googling around on this.

4

1 回答 1

0

你失去了你的缩进index.jade

尝试这个:

extends layout
block body
  if (authenticated)
    p Welcome back, #{me.first}
    a(href="/logout") Logout
  else
    p Welcome new visitor!
    ul
      li: a(href="/login") Login
      li: a(href="/signup") Signup
于 2012-10-17T22:36:01.767 回答