【发布时间】:2014-03-10 05:53:35
【问题描述】:
我从 KrakenJs 环境中的 DustJs 开始,我在使用 Dust 助手时遇到了一些麻烦。 事实上,我想创建一个助手,可以为我创建一个简单的引导按钮。
这是我的代码:
var dust = require('dustjs-linkedin');
if (!dust.helpers)
dust.helpers = {};
dust.helpers.bootstrapButton = function (chunk, context, bodies, params) {
var body = bodies.block || '',
options = params || {},
btnStyle = options.style || 'default',
btnClass = options.class || '',
btnSize = options.size || '';
btnStyle = 'btn btn-' + btnStyle;
if (btnSize)
btnSize = 'btn-' + btnSize;
return chunk.write('<button class="' + btnClass + btnStyle + btnSize + '">' + body + '</button>');
};
当我调用这个助手时,我有 body 的渲染函数而不是 body 的最终文本(按钮内容:“function body_3(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.write( "测试");}")
我尝试使用 chunk.render 但我有一个错误,因为我的最终 html 不是像 body 这样的函数。
你有什么想法吗?
问候, 纪尧姆
【问题讨论】: