如何在包中的Meteor中将模板添加到body中 [英] How to add a template to body in Meteor inside a package

查看:110
本文介绍了如何在包中的Meteor中将模板添加到body中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个模板:

I have this template:

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

在Meteor应用程序中,我可以用这种方式将它添加到body中(作为partial):

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

{{> sample}}

它的工作原理。我甚至测试过要调用Template.sample();在浏览器控制台中,它可以正常工作。

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

当我将其移动到我的包中时(即包文件夹中的sample.html文件),模板似乎消失了: code> Template.sample()不是一个函数,只要我调用函数,我甚至不能把它作为一个局部变量来呈现。

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.

我有这个代码的 package.js (显然这个包通过 packages正确地加载到我的应用程序中 .meteor ):

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?

推荐答案

解决了!添加以下行:

Solved! Add this line:

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

这篇关于如何在包中的Meteor中将模板添加到body中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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