2017-07-17 53 views
1

我正在使用updated documentation for Assemble.js,並且難以清楚地瞭解如何使用Handlebars在子文件夾中使用部分包含。無法渲染帶有句柄和assemblefile.js的部分

我發現在assemblefile.js中發現的部分配置的唯一有意義的參考文獻是不贊成使用的gulp-assemble doc site

Assemble.io沒有幫助,因爲它不是latest github repo的最新版本。

這裏是我的assemblefile.js:

'use strict'; 

var assemble = require('assemble'); 
var app = assemble(); 
var streamRename = require('stream-rename'); 
var markdown = require('helper-markdown'); 

app.helper('markdown', require('helper-markdown')); 

app.task('load', function(callback) { 
    app.partials(['templates/partials/*.hbs']); 
    app.pages(['templates/*.hbs']); 
    callback(); 
}) 

app.task('assemble', ['load'], function() { 
    return app.toStream('pages') 
    .pipe(app.renderFile()) 
    .pipe(streamRename({extname:'.html'})) 
    .pipe(app.dest("./")); 
}); 

app.task('default', ['assemble']); 

module.exports = app; 

我的文件結構:

root 
---/templates 
------index.hbs 
------/partials 
---------myPartial.hbs 

當我嘗試從index.hbs與調用部分:

{{> partials/myPartial.hbs}} 

的組裝任務產生此錯誤:

The partial partials/myPartial.hbs could not be found

如何通過簡單的彙編構建在子目錄中包含Handlebars partials?

回答

1

只需使用部分文件名的stem

{{> myPartial }} 

還有,試圖通過的關鍵在於找到部分稱爲partial一個內置的輔助(如myPartial)或其它屬性,如pathpartials/myPartial.hbs)有關模板如何一起工作

{{partial 'myPartial'}} 

更多信息可以在templates readme找到。這些文檔也鏈接到assemble readme

+0

謝謝!刪除額外的路徑和擴展工作(雖然我認爲我已經嘗試過,在故障排除)。 –