0

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?

Sagish
  • 1,065
  • 8
  • 13

2 Answers2

1

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.

exclsr
  • 3,329
  • 23
  • 27
0

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}
jmingov
  • 13,553
  • 2
  • 34
  • 37
  • That is ridiculous. Just use `title` in the `list.jade` and forget about `listTitle`. – Amberlamps Sep 24 '13 at 12:36
  • As I mentioned, my code is a simplified example. What I really want to do is use `include` in a loop and pass it different parameters each time, like a partial in Rails – Sagish Sep 24 '13 at 15:53