开发者

Create a jade default layout that has user information

开发者 https://www.devze.com 2023-04-13 02:40 出处:网络
I\'m creating a node.js project that uses express.js开发者_如何学Go and jade. I\'m trying to reate a default layout that when a user\'s logged in will show their avatar, new messages, and stuff like t

I'm creating a node.js project that uses express.js开发者_如何学Go and jade. I'm trying to reate a default layout that when a user's logged in will show their avatar, new messages, and stuff like that. Is this possible? I've tried searching google and got nothing back, even after replacing jade with django, rails, etc. Thank you for your consideration.


Yes, this is possible. you can create your own template and even override them using block and extend keywords of jade.

A block is simply a "block" of Jade that may be replaced within a child template, this process is recursive.

html
  head
    h1 My Site - #{title}
    block scripts
      script(src='/jquery.js')
  body
    block content
    block foot
      #footer
        p some footer content

Now to extend the layout, simply create a new file and use the extends directive as shown below, giving the path.

extends extend-layout

    block scripts
      script(src='/jquery.js')
      script(src='/pets.js')

    block content
      h1= title
      each pet in pets
        include pet

For details see "Template inheritance". https://github.com/visionmedia/jade

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号