Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor #车把中的if语句_Meteor_Handlebars.js - Fatal编程技术网

Meteor #车把中的if语句

Meteor #车把中的if语句,meteor,handlebars.js,Meteor,Handlebars.js,好的,我知道这是超基本的,但我已经盯着它看了两天,不明白为什么它不工作。我使用手柄如果助手有条件地呈现一个模板 以下是HTML: <head> <title>flash</title> </head> <body> {{#if isTrue}} {{> hello}} {{else}} {{> goodbye}} {{/if}} </body>

好的,我知道这是超基本的,但我已经盯着它看了两天,不明白为什么它不工作。我使用手柄如果助手有条件地呈现一个模板

以下是HTML:

<head>
    <title>flash</title>
</head>

<body>
    {{#if isTrue}}
        {{> hello}}
    {{else}}
        {{> goodbye}} 
    {{/if}}
</body>

<template name="hello">
    <h1>Hello!</h1>
</template>

<template name="goodbye">
    <h1>Goodbye!</h1>
</template>

我希望{{>hello}}模板能够呈现,但是运气不好。我刚得到{{>再见}模板。这是奇怪的,因为我有其他项目,我已经成功地做到了这一点。这里我肯定遗漏了一些明显的东西。

变量必须在模板中才能工作。因此,将正文内容放在模板中:

<body>
    {{> body}}
</body>

<template name="body">
    {{#if isTrue}}
        {{> hello}}
    {{else}}
        {{> goodbye}} 
    {{/if}}
</template>
注:

现在不推荐使用

新语法如下所示:

Template.test.helpers({
“isTrue”:函数(){
返回true;
}

});使用Meteor 1.2.0.2,您可以这样做

Template.hello.helpers({
   isTrue() { return true }
});

嗨,Sjoerd,我重新实现了它,它成功了。非常感谢。奇怪的是,我有另一个项目在常规HTML正文中使用if helpers,它工作得很好。很奇怪,但这次修正让我回到了正轨。再次感谢。
Template.body.helpers
  isTrue: -> true
Template.body.isTrue = -> true
Template.hello.helpers({
   isTrue() { return true }
});