Multiple extend blocks

164 views
Skip to first unread message

Daniël Terwiel

unread,
May 25, 2014, 7:31:25 AM5/25/14
to jad...@googlegroups.com

So I'm using jade to build a couple of webpages, but my landingpage differs in the other pages in the way that it hasn't got a menu. Except for that it shares the same header and footer. My problem is that I'd like to conditionally include menu.jade into conversion to html. I'd like to do something like this:

base.jade:

doctype html
  head
    title= title
  body
    block menu
    block content
    include footer

menu.jade

extends base
  ul
    li Home
    li Contact

index.jade:

extends base
block content
  p hello landingpage

page.jade

extends base
block content
  p hello subpage

The thing is: when I convert index.jade everything is fine; my pages looks like I want it to. But when I convert page.jade I somehow would like to include menu.jade as well,o I don't have to rewrite my menu across all subpages.

Marcel Miranda

unread,
May 25, 2014, 10:44:29 PM5/25/14
to jad...@googlegroups.com
You could do something like:

base_with_menu.jade

extends base
  block menu
    ul
      li Home
      li Contact


and just use 

extends base_with_menu
block content
  h1 Whatever


on the pages you want a menu
and extends base on the ones you don’t.


--
You received this message because you are subscribed to the Google Groups "Jade" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jadejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniël Terwiel

unread,
May 26, 2014, 4:16:44 PM5/26/14
to jad...@googlegroups.com
Hi Marcel,

That's exactly what I went for. I was hoping for some genius with a solution that was more dry than mine, but I guess I'll just go with this one. Thanks a lot for your response, much obliged.

Daniël

Jackie Enders

unread,
Jan 17, 2015, 12:25:23 AM1/17/15
to jad...@googlegroups.com
Even though this is super duper old by web standards, I do have a better solution in the concept of includes...

for example:

base.jade is the same, but rather than doing menu.jade as an extend, just write is like a snippet type thing like this:

ul
  li Home
  li Contact

and then your index.jade would remain the same, but your page.jade you would write it like this:


include page.jade

block content
  p hello subpage

and that should work.
Reply all
Reply to author
Forward
0 new messages