如何在包中的Meteor中将模板添加到body中

编程入门 行业动态 更新时间:2024-10-24 11:15:51
本文介绍了如何在包中的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正确地加载到我的应用程序中

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中

本文发布于:2023-11-22 19:15:27,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   包中   模板   如何在   Meteor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!