如何将JSON数据传递到Nunjucks模板中? [英] How can I pass JSON data into a Nunjucks template?
本文介绍了如何将JSON数据传递到Nunjucks模板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Nunjucks模板,但想传入我自己的JSON数据以在模板上使用.
I want to use Nunjucks templates but want to pass in my own JSON data to be used on the templates.
这里的文档很少.
https://mozilla.github.io/nunjucks/templating.html
谢谢.
推荐答案
您可以使用 gulp-data 允许您将json文件传递到用于渲染Nunjucks的任务运行程序.
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'))
});
这篇关于如何将JSON数据传递到Nunjucks模板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文