2015-08-14 170 views
0

我想抽象一些代码,并希望利用dust.helpers渲染一个parial。DustJS:渲染部分通过帮助器

我的当前设置:

{> "includes/components/link" /} 

理想设置:

{@uiComponent name="link" /} 

我的助手:

dust.helpers.uiComponent = function (chunk, context, bodies, params) { 
    return dust.render('includes/components/' + name, context, function (err, out) { 
     chunk.end(out); 
    }); 
}; 

我也尝试了一些其他的东西,没有用。

是的,我试着看文档。 :(

任何建议,将不胜感激!

+0

你要处理的部分以一种特殊的方式还是这只是抽象掉 – Interrobang

+0

主要是抽象的文件路径的路径...但目前想拥有这个例如,如果需要,可以操纵数据。 – peduarte

回答

1

灰尘,助手返回块,所以你需要使用大块的方法来恢复你的帮手,而不是dust.render

在这种情况下,你与泛音的工作,所以你要chunk.partial:?!

dust.helpers.uiComponent = function (chunk, context, bodies, params) { 
    var name = context.resolve(params.name); 
    return chunk.partial('includes/components/' + name, context, params); 
}; 
+0

非常感谢,会给这个去! – peduarte

+0

什么是'context.resolve'? – peduarte

+0

它评估一个参数,如果你没有传递一个字符串,而是传递类似'name =“{foo}”' – Interrobang