我希望Assemble获取我的源文件(/src/hbs/*.hbs)并创建两个单独的文件(例如,一个包含页眉、页脚和导航,而另一个仅包含代码片段)。我已经创建了两个模板(默认(整页)和空(只是一个包装器))。我正在使用gulp assemble,它看起来像这样:
gulp.task('assemble', function () {
assemble.layouts(paths.templates.layouts);
assemble.partial(paths.templates.partials);
gulp.src(paths.sources.handlebars)
.pipe(gulpAssemble(assemble, { layout: 'default' }))
.pipe(prettify())
.pipe(rename({basename:'index', extname:'.html'}))
.pipe(gulp.dest(paths.build.www));
});
gulp.task('snippet', function(){
assemble.layouts(paths.templates.layouts);
assemble.partial(paths.templates.partials);
gulp.src(paths.sources.handlebars)
.pipe(gulpAssemble(assemble, { layout: 'empty' }))
.pipe(prettify())
.pipe(rename({extname:'.html'}))
.pipe(gulp.dest(paths.build.www));
});当我运行gulp时,这两个文件都包装在默认模板中。我遗漏了什么?
发布于 2016-08-10 00:46:28
Brandon Merritt示例中的代码基于Assemble的0.6.0测试版API。
这就是如何在assemble now (从v0.17.0开始)中实现这一点:
var assemble = require('assemble');
var app = assemble();
// use a task for loading collections, so we can ensure views
// are loaded before `src` files, or re-loaded when watch is triggered
app.task('load', function(cb) {
app.layouts(paths.templates.layouts);
app.partial(paths.templates.partials);
cb();
});
app.task('assemble', ['load'], function() {
// with assemble or gulp, you need to return the stream
// or call the callback to signal task completion
return app.src(paths.sources.handlebars)
.pipe(app.renderFile())
.pipe(rename({extname:'.html'}))
.pipe(app.dest(paths.build.www));
});
app.task('snippet', ['load'], function() {
return app.src(paths.sources.handlebars)
.pipe(app.renderFile({ layout: 'default' }))
.pipe(rename({basename:'index', extname:'.html'}))
.pipe(app.dest(paths.build.www));
});发布于 2015-05-01 23:44:39
我必须在流程中定义更高级别的组装组件,并将其修复。
assemble.layouts(paths.templates.layouts);
assemble.partial(paths.templates.partials);
gulp.task('assemble', function () {
gulp.src(paths.sources.handlebars)
.pipe(gulpAssemble(assemble, { layout: 'empty' }))
.pipe(rename({extname:'.html'}))
.pipe(gulp.dest(paths.build.www));
});
gulp.task('snippet', function () {
gulp.src(paths.sources.handlebars)
.pipe(gulpAssemble(assemble, { layout: 'default' }))
.pipe(rename({basename:'index', extname:'.html'}))
.pipe(gulp.dest(paths.build.www));
});https://stackoverflow.com/questions/29971665
复制相似问题