Search code examples
gruntjsassemble

Dynamic YFM with single template and multiple JSON files


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?


Solution

  • 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