gpt4 book ai didi

javascript - 灰尘JS : Render partial via a Helper

转载 作者:行者123 更新时间:2023-12-03 09:13:28 31 4
gpt4 key购买 nike

我正在尝试抽象一些代码,并想利用dust.helpers来渲染部分。

我当前的设置:

{> "includes/components/link" /}

我的理想设置:

{@uiComponent name="link" /}

我的 helper :

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

我还尝试了许多其他方法,但没有任何效果。

是的,我尝试查看文档。 :(

如有任何建议,我们将不胜感激!

最佳答案

在 Dust 中,助手会返回 Chunk,因此您需要使用 Chunk 方法从助手中返回,而不是 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);
};

关于javascript - 灰尘JS : Render partial via a Helper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32013937/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com