0
맞춤 블록 도우미에서 params를 전달하고 컴파일하고 싶습니다. params가 hash-object 안에 있다는 것을 알았지 만 어떻게 부분으로 컴파일 할 수 있습니까?핸들 바를 통한 변수 전달 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이 파일
기능하지
다른 부분에 내 blockhelper에서 PARAM을 통과<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
전화 그리고 그것은 가능하다?
var output = template({
"addClass": options.hash.addClass,
"id": options.hash.id,
"body": options.fn(this)
});
는 I는 "ID"의
{{#injectHtml "flyout" flyoutClass='navigation__item'id='myUniqueID'}}
및하지만 [1] PARAM 컴파일되지 나의 부분 버튼
<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>
그것을 이용하여 부분이 연장하고자 , [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 고맙습니다;) 작동하지만 params를 동적으로 추가 할 수있는 방법이 없습니까 ?? 왜냐하면 나는 또한이 블록 헬퍼를 내 fakescroller, 드롭 다운과 같은 다른 부분적인 부분을위한 generell 도우미로 사용하기를 원하기 때문이다. –