0
我想传递和编译我的自定义块帮助中的参数。我发现params在一个哈希对象内,但是我怎样才能将它们编译成部分?通过句柄传递变量blockhelper
我想要参数flyoutClass
被编译到我的部分。一切工作正常,但在我的参数的时输出应该是地方留成空...
车把帮手
module.exports.register = function (Handlebars, context) {
Handlebars.registerHelper('injectHtml', function(name, options) {
console.log(options.hash); //yeah my param
var partial = Handlebars.partials[name];
var template = Handlebars.compile(partial);
//var template = Handlebars.compile(partial)(options.hash); *
var output = template({"body": options.fn(this)});
return new Handlebars.SafeString(output);
//return new Handlebars.SafeString(output(options.hash)); *
//return new Handlebars.SafeString(partial(output)); *
})
};
我已经尝试了一些东西,但我总能得到的警告......
警告:字符串不是一个函数
.hbs文件
<div class="flyout {{flyoutClass}}">
<button>flyout-button</button>
<div class="flyout__content">
{{{body}}}
</div>
</div>
叫我blockhelper
{{#injectHtml "flyout" flyoutClass='navigation__item'}}
<div class="wrapper">
<h3>Headline</h3>
<p>some copy</p>
<button>CTA</button>
</div
<div class="wrapper">
<h3>Headline</h3>
<p>some copy</p>
<button>CTA</button>
</div>
{{/injectHtml}}
UPTADE
,并有可能从我的blockhelper设置了一个param传递到另一个部分?
var output = template({
"addClass": options.hash.addClass,
"id": options.hash.id,
"body": options.fn(this)
});
我想延长这一部分与 “ID”
{{#injectHtml "flyout" flyoutClass='navigation__item'id='myUniqueID'}}
,还可以使用它在我的部分按钮
<div class="flyout {{flyoutClass}}">
{{>button btn="icon-text" id="{{id}}"/*[1]*/ icon="arrow-down"label="klick me"}}
<div class="flyout__content" aria-labelledby="{{id}}"/*[2]*/>
{{{body}}}
</div>
</div>
但在[1]的参数是未编译,[2]工作正常。
<div class="flyout navigation__item">
<a href="#" id="{{id}}"/*[1]*/ aria-expanded="false">
<div class="flyout__content" aria-labelledby="myUniqueID"/*[2]*/>
//html content
</div>
</div>
WOW谢谢你;)的工作,但没有办法动态地添加参数?因为我也想使用这个blockhelper作为像我的fakescroller,dropdown等其他部分的generell助手。.. –