我結束了使用this gist的代碼片段。 我修改它以適合我的需要。
這裏是我的結果(並回答我自己的問題):
dust.helpers.myHelper = function(chunk, context, bodies, params) {
var output = "";
chunk.tap(function (data) {
output += data;
return "";
}).render(bodies.block, context).untap();
console.log(output); // This will now show the rendered result of the block
return chunk;
}
這也可以被抽象爲一個單獨的函數:
function renderBlock(block, chunk, context) {
var output = "";
chunk.tap(function (data) {
output += data;
return "";
}).render(block, context).untap();
return output;
}
dust.helpers.myHelper = function(chunk, context, bodies, params) {
var output = renderBlock(bodies.block, chunk, context);
console.log(output); // This will now show the rendered result of the block
return chunk;
}