col*_*rco 11 package handlebars.js meteor
我有这个模板:
<template name="sample">
<h1>Sample</h1>
</template>
Run Code Online (Sandbox Code Playgroud)
在Meteor应用程序中,我可以通过这种方式将其添加到正文中(作为部分):
{{> sample}}
Run Code Online (Sandbox Code Playgroud)
有用.我甚至测试过调用Template.sample(); 在浏览器控制台内,它工作.
当我在我的包中移动它(即我的包文件夹中的sample.html文件)时,模板似乎消失了:Template.sample() is not a function每当我调用该函数时我都会得到它,我甚至无法将其渲染为部分.
我有一个package.js这个代码(显然,包通过packages文件正确加载到我的应用程序中.meteor):
Package.on_use(function (api) {
api.add_files(['sample.html', 'sample.js'], 'client');
});
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用? 如何从包装中将(反应)模板附加到身体上?
col*_*rco 30
解决了!添加此行:
api.use(['templating'], 'client');
Run Code Online (Sandbox Code Playgroud)
Mic*_*oon 12
在html文件之前包含文件也很重要js
api.add_files("client/sampleTemplate.html", "client");
api.add_files("client/sampleTemplate.js", "client");
Run Code Online (Sandbox Code Playgroud)