Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an object's properties as the locals to an include in Jade?

I'd like to pass an object inside a loop as follows;

data structure:

things = [
      {
          title: 'foo'
        , description: 'bar'
      }
    , {
          title: 'baz'
        , description: 'bam'
      }
];

index.jade:

- for thing in things
    include things-template

In the above format, I'd like to be able to specify a parameter of some sort as "locals" for that include.

things-template.jade:

li
  h3 #{title}
  p #{description}

Is this possible, or do I need to assign it to another variable and reference it inside my "thing-template"?

like image 855
Eric Martindale Avatar asked Apr 20 '12 01:04

Eric Martindale


1 Answers

As the newest jade version (0.27.4)
You can pass object reference as the same name of template

for thing in things
  include thing

will automatic include ./thing.jade with thing as object
in thing.jade:

li
  h3 #{thing.title}
  p #{thing.description}
like image 104
Jimchao Avatar answered Nov 18 '22 12:11

Jimchao