Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 292
collimarco Avatar asked Nov 17 '12 11:11

collimarco


2 Answers

Solved! Add this line:

api.use(['templating'], 'client');
like image 158
collimarco Avatar answered Sep 29 '22 13:09

collimarco


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");
like image 34
Micha Roon Avatar answered Sep 29 '22 13:09

Micha Roon