I want to use Nunjucks templates but want to pass in my own JSON data to be used on the templates.
The documentation here is pretty sparse.
https://mozilla.github.io/nunjucks/templating.html
Thank you.
You can use gulp-data which allows you to pass json files to the task runner you're using to render Nunjucks.
JSON templates allow you to control the look and feel of different pages of the online store using sections. JSON templates are data files that store a list of sections to be rendered, and their associated settings. Merchants can add, remove, and reorder these sections using the theme editor.
You can use gulp-data which allows you to pass json files to the task runner you're using to render Nunjucks.
gulp.task('nunjucks', function() {
return gulp.src('app/pages/**/*.+(html|nunjucks)')
// Adding data to Nunjucks
.pipe(data(function() {
return require('./app/data.json')
}))
.pipe(nunjucksRender({
path: ['app/templates']
}))
.pipe(gulp.dest('app'))
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With