什么原因导致“模板未定义"?在流星? [英] What causes "Template is not defined" in Meteor?

查看:22
本文介绍了什么原因导致“模板未定义"?在流星?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个极其简单的 Meteor 应用程序在加载时抛出 Template is not defined 错误.该应用程序本质上与样板项目相同(meteor create),只是分成服务器/客户端/公共目录.

This extremely simple Meteor app is throwing a Template is not defined error on load. The app is essentially identical to the boilerplate project (meteor create), just split into server/client/public directories.

Meteor 似乎试图在全局模板对象实际准备好之前呈现 Handlebars template 标签.当我可以进入 JS 控制台并输入模板"时,它就在那里.

Meteor seems to be trying to render the Handlebars template tags before the global Template object is actually ready. By the time I can get to the JS console and type "Template", it is there.

我做错了什么,还是计时错误?

Have I done something wrong, or is this a timing bug?

推荐答案

嗯,也许这会解决你的问题:

Hm, perhaps this will solve your issue:

注意 body 标签包含模板名称但不包含模板:

Note that the body tag includes the template name but not the template:

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

<template name="hello">
  {{greet}}
</template>

另外,请注意.greet"指的是{{greet}}:

Also, note that ".greet" refers to {{greet}}:

if (Meteor.isClient) {
  Template.hello.greet = function () {
    return "Hey!";
  };
}

因此,问题是您不能在正文中使用模板.相反,主体使用 {{> hello}} 调用模板,就像上面的代码一样.

So, the issue was that you can't have a template inside the body. Instead, the body calls the template with {{> hello}} as in the above code.

这篇关于什么原因导致“模板未定义"?在流星?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆