Have gulp / nunjucks iterate on a template based on json data file -
i using gulp-data attach json file file.data in gulp stream. want gulp read property data, render template value, increment value , repeat until condition met ( loop in js ). can nunjucks access data on file.data object, not gulp, , haven't found answered question getting gulp perform loop. i'm trying create static pages similar, except incrementing thru -01.html , -01.jpg each. here's basic idea far, not right , needs gulp-rename or similar well:
var getjsondata = function(file) { return require(path.dirname(file.path) + '/' + path.basename(file.path, '.nunjucks') + '.json'); }; gulp.task('json', function() { return gulp.src('./build/nunjucks/pages/**/*.nunjucks') .pipe(data(getjsondata)) .pipe( gulpif(data.pages, function() { (i = 0, < pages, i++) { .pipe(nunjucksrender({ path: ['./build/nunjucks/templates'] })); .pipe(gulp.dest('./build')); data.number++; } })) // need loop here .pipe(nunjucksrender({ path: ['./build/nunjucks/templates'] })) .pipe(gulp.dest('./build')); });
Comments
Post a Comment