Reputation: 1065
I wish to pass Jade includes with local variables coming from the controller. My data is simplified for this example, of course I'm looking to achieve something more complicated.
i.e
controller:
res.render("index", {title: "Lovely"})
index.jade:
section
include list, {listTitle: title}
list.jade:
h3 #{listTitle}
but listTitle
is not passed to the include
,
In Rails we do this by assigning locals to partials , how can this be achieved in Jade?
Upvotes: 0
Views: 1025
Reputation: 3357
In Jade, partials are called mixins. For instance:
controller:
res.render("index", {title: "Lovely"})
index.jade:
include mixins
section
+list(title)
mixins.jade:
mixin list(listTitle)
h3 #{listTitle}
The mixin is defined in mixins.jade. It is then added to index.jade by using the + sign.
Upvotes: 1
Reputation: 14003
Controller:
var listTitle = [{ title: 'foo' }, { title: 'baz' }];
var title = "Lovely";
res.render("index", {title: title, listTitle: listTitle})
index.jade:
section
for lists in listTitle
include list
list.jade:
h3 #{lists.title}
Upvotes: 0