我想創建一個使用Meteor的自定義幫助器。繼到文檔在這裏: https://github.com/meteor/meteor/wiki/Handlebars如何在流星的助手中使用多個參數?
我試圖定義我的助手如下:
Template.myTemplate.testHelper = function(foo, bar, options) {
console.log(foo);
console.log(bar);
}
我的模板是這樣的:
<template name="myTemplate">
{{#testHelper "value1" "value2"}}
{{/testHelper}}
</template>
看着我的控制檯輸出,我預計看到2行輸出:
value1
value2
但是我的主機看起來像:
value1
function (data) {
// don't create spurious annotations when data is same
// as before (or when transitioning between e.g. `window` and
// `undefined`)
if ((data || Handlebars._defaultThis) ===
(old_data || Handlebars._defaultThis))
return fn(data);
else
return Spark.setDataContext(data, fn(data));
}
請注意,我是完全新的流星,並handlebars。我認爲使用下劃線會更快樂,但流星瀏覽的文檔幾乎全部強調了下劃線。我做錯了定義我的幫助函數嗎?它似乎沒有看到第二個參數「bar」,而是將其解釋爲選項。 (注意:如果我console.log(選項)它返回'未定義')。
流星版本0.4.0(8f4045c1b9)
如果您需要{{#if}} Content {{/ if}}樣式幫助程序,這無效。 – Donflopez
可以在這種情況下合併幫助者:'{{#if testHelper「v1」「v2」}}一些模板{{/ if}}' – Matanya
'Handlebars.registerHelper'應該放在哪裏? –