0

I have multiple JSON files being looped over and populating a single template as seen in this question: Using Assemble, generate HTML files from multiple data files using one template file?

Each one of my JSON files has a title and description - how can I load these into the template (generally done with YFM) so that each generated HTML file has a unique title and description?

Community
  • 1
  • 1
Patrick Ng
  • 30
  • 5
  • I tried concatenating the YFM block as a string to the beginning of the template but that doesn't work. Attached the gist here: [link](https://gist.github.com/patrickng/c138c4ac8e6891fecbfc) `console.log(concatModProjectTemplate)` shows the right format but the resulting HTML does not show the title or description. – Patrick Ng Oct 08 '14 at 15:29

2 Answers2

1

In assemble v0.4.x when you pass in the pages as a data object (like you're doing), only the data object is used. The data parsed out of the page content is not used.

Try updating your code to add the properties to data instead of concating the template:

// read in the data file
var data = grunt.file.readJSON(filepath);
data.title = data.project.projectTitle;
data.description = data.project.meata.description;

This is fixed in v0.6.x

doowb
  • 3,372
  • 1
  • 17
  • 25
0

Turns out that it's not important for the projectTemplate to have the YFM injected up top. To get it to show up, I just modified the data object with the title and description.

In essence, this gist https://gist.github.com/patrickng/c138c4ac8e6891fecbfc becomes https://gist.github.com/patrickng/5d36eb9ada2d353ff98e

Patrick Ng
  • 30
  • 5