Templates 有哪些Meteor模板辅助函数可用于子模板?

Templates 有哪些Meteor模板辅助函数可用于子模板?,templates,meteor,Templates,Meteor,我在另一个模板中有一个Meteor(v0.8)模板: <template name="vehicles"> {{wheels}} {{>hovercraft}} </template> <template name="hovercraft"> {{eels}} </template> 但是没有找到eels。当然,在内部模板(hovercraft)上定义它可以: 子模板如何继承模板函数的规则是什么?气垫船能否继承车辆

我在另一个模板中有一个Meteor(v0.8)模板:

<template name="vehicles">
    {{wheels}}
    {{>hovercraft}}
</template>

<template name="hovercraft">
    {{eels}}
</template>
但是没有找到
eels
。当然,在内部模板(
hovercraft
)上定义它可以:

子模板如何继承模板函数的规则是什么?
气垫船
能否继承
车辆
功能?当我把大模板重构成小模板时,我经常发现自己需要这个

谢谢。

使用包从模板继承帮助程序

您还可以像这样将参数传递给子模板:

<template name="tParent">
   {{> tChild h1=helper1 h2=helper2}}
</template>

<template name="tChild">
   {{h1}}
   {{h2}}
</template>

Template.tParent.helpers({
    helper1: function () {
      return "helper1"
    },
    helper2: function () {
      return "helper2" 
    }
  });

{{>tChild h1=helper1 h2=helper2}
{{h1}}
{{h2}
Template.tParent.helpers({
helper1:函数(){
返回“helper1”
},
helper2:函数(){
返回“helper2”
}
});
问题是上面的方法传递了helper的结果,而不是引用它。 然而,在某些情况下,它仍然是有用的

Template.hovercraft.eels = function() { console.log("eels in the hovercraft"); }
<template name="tParent">
   {{> tChild h1=helper1 h2=helper2}}
</template>

<template name="tChild">
   {{h1}}
   {{h2}}
</template>

Template.tParent.helpers({
    helper1: function () {
      return "helper1"
    },
    helper2: function () {
      return "helper2" 
    }
  });