techie.brandon
techie.brandon

Reputation: 1678

Jade partial inheritance block/extend implementation

I have been in the practice of using partials across my applications for some time now across a number of different frameworks; I am baffled by Jade's implementation, or my incorrect usage, and would like to get other exploiter's experiences and any corrections to my understanding.

Folder structure:

$ cd <app_root>/views
$ ls
  myHoverToolTip.jade
  layout.jade

Caller:

httpJadeViewerRsp = (req, res) -> res.render('myHoverToolTip.jade', { variable: 'here' })

myHoverToolTip.jade

extends layout

block myHoverToolTip
  .some-div
    h1 Awesome-O Rocks

layout.jade

<...bunch of jade markup...>
.div
  block myHoverToolTip
    h5 Content to remove

This works in a small number of use-cases where you are just providing a page and are looking for a standard way to provide a layout. However deviating from this and using partials in a more module fashion to DRY things up and you find this implementation of extends/block leaves me scratching my head. I want to break my tool-tip into a partial to be reused across a data grid (of course passing a number of variables to the partial, so forget about includes), this implementation forbids me from having this ability. Can anyone provide me further insight, correct my usage, or direct me to a better NodeJs-ready templating library that will work with Express 3

Upvotes: 0

Views: 1203

Answers (2)

Joshua
Joshua

Reputation: 3603

As of Aug 2012 and Express 3, "partials" support is removed, but the functionality is still available via the expression "include [yourtemplatename]" without the quotes or brackets.

An alternative to Jade which I have also found useful is the EJS templating, which is a little more ASP.NET / JSTL-like.

Edit: In both cases, parent contexts and variables available are accessible by includes.

Upvotes: 0

zemirco
zemirco

Reputation: 16395

Sounds like mixins might help you.

Upvotes: 1

Related Questions