How to add a template to body in Meteor inside a package

試著忘記壹切 提交于 2019-12-19 05:23:12

问题


I have this template:

<template name="sample">
  <h1>Sample</h1>
</template>

Inside a Meteor app I can add this to body this way (as a partial):

{{> sample}}

It works. I've even tested to call Template.sample(); inside browser console and it works.

When I move this inside my package (i.e. a sample.html file inside my package folder) the template seems to disappear: I get Template.sample() is not a function whenever I call the function and I am not even able to render it as a partial.

I have a package.js with this code (and obviously the package is correctly loaded inside my app through packages file in .meteor):

Package.on_use(function (api) {
  api.add_files(['sample.html', 'sample.js'], 'client');
});

Why this doesn't work? How can I append a (reactive) Template to body from my package?


回答1:


Solved! Add this line:

api.use(['templating'], 'client');



回答2:


it is also important to include the html file before the js

api.add_files("client/sampleTemplate.html", "client");
api.add_files("client/sampleTemplate.js", "client");



回答3:


Include in file packages.js of package

before

api.use('meteor-platform');
api.use('ui');`

after first ".html" files, after ".js" files

api.addFiles('filename.html','client');
api.addFiles('filename.js','client');`


来源:https://stackoverflow.com/questions/13430102/how-to-add-a-template-to-body-in-meteor-inside-a-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!