【发布时间】:2017-01-16 03:04:32
【问题描述】:
我正在使用 Handlebars 和 Gulp 构建一个静态站点。这是我的文件夹结构:
app/
content/
intro.json
header.json
faq.json
features.json
footer.json
templates/
home.hbs
partials/
home-section.hbs
header.hbs
footer.hbs
index.html
Gulpfile.js
home.hbs的内容是这样的:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
{{> header}}
{{> home-section}}
{{> home-section}}
{{> home-section}}
{{> footer}}
</body>
</html>
我想将intro.json、faq.json 和features.json 传递给每个home-section 部分,并将@987654327@ 传递给header 和footer.json 到页脚。
这是我目前在 Gulpfile 中的内容:
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var rename = require('gulp-rename');
gulp.task('html', function() {
return gulp.src('./app/templates/*.hbs')
.pipe(handlebars({}, {
ignorePartials: true,
batch: ['./app/templates/partials']
}))
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest('build'));
});
我无法弄清楚如何一次传递多个 JSON 文件,尤其是传递给home-sections。提前致谢!
【问题讨论】:
标签: json gulp handlebars.js gulp-compile-handlebars