Question

The assemble.io documentation gives some examples of using simple JSON as a data source, such as:

{
  "title": "Assemble" ,
  "author": "Brian Woodward" 
 }

But, what if I wanted to use a more complex JSON structure for my data (to display a list of books on a single page)? How can that be done?

{
    "books": [
        {
            "title": "Book A",
            "author": "Fred"
        },
        {
            "title": "Book 47",
            "author": "Joe"
        }
    ]
}
Était-ce utile?

La solution

Let say your library.json contain:

{
    "books": [
        {
            "title": "Book A",
            "author": "Fred"
        },
        {
            "title": "Book 47",
            "author": "Joe"
        }
    ]
}

Use {{each}} (Assemble use handlebarjs for default templating) to display a list of books on a single page:

{{#each library.books}}
  {{title}} - {{author}}
{{/each}}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top