Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save keyurshah/b7a80f31df91440c86f33f49e9dc0fd9 to your computer and use it in GitHub Desktop.
Save keyurshah/b7a80f31df91440c86f33f49e9dc0fd9 to your computer and use it in GitHub Desktop.
Multiple blocks in Jade/Pug mixins
//- Multiple blocks in jade mixins? #1693
//- https://github.com/pugjs/pug/issues/1693
//- [Issue on github]
//- https://github.com/pugjs/pug/issues/1693
h2 Issue
p
a(href='https://github.com/pugjs/pug/issues/1693' , target="_blank") Multiple blocks in jade mixins?
hr
//- [Defines]
- BlockAmbry = {}
mixin block-set(mixin , blockid)
if block
- BlockAmbry[mixin] = BlockAmbry[mixin] || {}
- BlockAmbry[mixin][blockid] = function() { return block.call(this) };
mixin block-call(mixin , blockid)
- BlockAmbry[mixin][blockid].call();
//- [Example mixin]
mixin example-mixin-name(name , cb)
block
.template
.layout-left
+block-call('example-mixin-name','layout-left')
.layout-right
+block-call('example-mixin-name','layout-right')
//- [Here we go...]
.wrapper
//- set before mixin call...
+block-set('example-mixin-name','layout-left')
p lorem ipsum
+block-set('example-mixin-name','layout-right')
p dolor sit amet
+example-mixin-name()
//- ...or within block
+example-mixin-name()
+block-set('example-mixin-name','layout-left')
p consectetur adipiscing elit
+block-set('example-mixin-name','layout-right')
p sed do eiusmod tempor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment