Dredok
Dredok

Reputation: 805

jade blocks how to reuse code properly?

How could I insert arbitrary code ("partials" style) using blocks in jade (after express 3.0) ?

lets say i have various templates which inherit from "layout.jade", each one render different views but I have common code (which fits into partials).

The only solution I have thought is making a common parent with the common code but it seems weird as a hell...

parent
body
 block no_common_1
 block common_1
     ... code
 block no_common_2
 block common_2
     ... code

child1
 block no_common_1
      ... code
 block common_1
 block no_common_2
      ... code
 block common_2

child2
 block no_common_1
      ... code
 block common_1
 block no_common_2
      ... code
 block common_2

is this sound? could I skip some blocks here and there? what about altering the order?

thanks a lot!

Upvotes: 1

Views: 1140

Answers (1)

Pickels
Pickels

Reputation: 34680

Partials was removed from express.js but Jade still has them. You have to use include + the path to your partial.

 include ../path/to/partial

Upvotes: 2

Related Questions