Skip to content

Actual example of gulp-data use #56

@WojoJustin

Description

@WojoJustin

I've only been able to make this work by providing a function to process a JSON file directly through the twig initialization in gulp:

return gulp.src(paths.src)
    .on('error', handleErrors)
    .pipe(twig({
              data: {
                "tables": function(file) {
                  var dataPath = path.resolve(config.root.src, config.tasks.html.src, config.tasks.html.dataFile);

                  var data = JSON.parse(fs.readFileSync(dataPath, 'utf8'));
          
                  return data;
                }
              }
    }))
    .on('error', handleErrors)
    .pipe(gulp.dest(paths.dest))

running:

.pipe(data(function (file) {
    return JSON.parse(fs.readFileSync('./examples/' + path.basename(file.path) + '.json'));
}))
.pipe(twig())

has not worked at all. gulp-data has been returning the actual gulp information and not my json file data. There's also no way to configure how this data is defined in the template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions