我正在尝试编写一个带有自己的模板的包。在我的 package.js
中我正在做
api.imply([
'meteor-platform',
...
]);
api.addFiles([
'client/templates/brain_layout.html',
...
], 'client');
api.addFiles([
'client/templates/brain_layout.js',
...
], 'client');
在我的brain_layout.html
中我正在做
<template name="brainLayout">
<div id="wrap">
...
</div>
{{> footer}}
</template>
在我的brain_layout.js
中我正在做
if (Meteor.isClient) {
Meteor.startup(function () {
console.log(Template);
console.log(Template.brainLayout);
Template.brainLayout.events({
...
});
});
}
结果是我通过iron router得到一个错误,说无法找到名为“brainLayout”或“brainLayout”的模板。你确定你定义了它吗?
并且在控制台中我得到TypeError: undefined is not an object (evaluating 'Template.brainLayout.events')
以及我的的输出>console.log
行。这些产生:一个正确定义的 Template
构造函数和一个 未定义 Template.brainLayout
。
我已经浏览了几个指南和堆栈溢出讨论,但找不到原因。有什么想法吗?
最佳答案
确保在 package.js
中使用 api.use('templated', 'client');
。如果没有这种依赖性,包模板将无法被识别。
另请注意,如果该文件仅添加到客户端,则不需要在 brain_layout.js
中检查 if (Meteor.isClient)
。
关于javascript - meteor 包: Templates not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002443/