简体   繁体   English

使用Iron Router在流星包中包含HTML模板

[英]Including an HTML Template in a Meteor Package with Iron Router

I am trying to mimic the Telescope application structure in my own demo Meteor application. 我试图在自己的演示Meteor应用程序中模仿Telescope应用程序结构。 The way they have things setup means that all code is located within sub-packages, including HTML templates and such. 他们进行事物设置的方式意味着所有代码都位于子包中,包括HTML模板等。

I have my Meteor app setup so that I have the following: 我已设置流星应用程序,因此需要执行以下操作:

  • client 客户
    • layout.html (Contains head tag, used as the "base" for the page) layout.html(包含head标记,用作页面的“基础”)
  • server 服务器

    • index.js (Contains the configuration for the Iron router, such as the default layoutTemplate ) index.js(包含Iron路由器的配置,例如默认的layoutTemplate
  • packages

    • myapp-ui MYAPP的UI
      • client 客户
        • dashboard.html dashboard.html
      • myapp-ui.js MYAPP-ui.js
      • package.js package.js

Inside of the package.js file in my package, I have the following code when trying to load the HTML template: 在我的包中的package.js文件中,当尝试加载HTML模板时,我有以下代码:

Package.describe({
    name: 'myapp-ui',
    version: '0.0.1',
    documentation: null
});

Package.onUse(function (api) {
    api.versionsFrom('1.1.0.2');

    api.use([
        'iron:router'
    ]);

    api.addFiles([
        'client/dashboard.html'
    ]);

    api.addFiles('myapp-ui.js');
});

The myapp-ui.js file contains code to try and get the dashboard.html code into my application: myapp-ui.js文件包含尝试将dashboard.html代码添加到我的应用程序中的代码:

Router.route('/', function() {
    this.render('Dashboard');
});

The dashboard.html template is simply: dashboard.html模板很简单:

<template name="dashboard">
    <p>Hello, world!</p>
</template>

The problem is, when visiting the localhost:3000 page that should load the dashboard, I get an error: 问题是,当访问加载仪表板的localhost:3000页面时,出现错误:

Couldn't find a template named "Dashboard" or "dashboard". Are you sure you defined it?

I am slightly confused, because I obviously have a template HTML file loaded with a template tag named "dashboard", and this file is loaded inside my package with api.addFiles . 我有些困惑,因为显然我有一个模板HTML文件,该文件加载了名为“ dashboard”的模板标签,并且此文件通过api.addFiles加载到我的包中。 Do I need to use some other package to enable loading of HTML inside of packages, or is my code just incorrect? 我是否需要使用其他软件包才能在软件包内部加载HTML,还是我的代码不正确?

Stick to either uppercase of lowercase syntax for your template name, at the moment you have both <template name="dashboard"> and this.render('Dashboard'); 现在,您同时拥有<template name="dashboard">this.render('Dashboard');模板名称,请使用大写或小写语法this.render('Dashboard'); .

Did you actually add your package to the app using meteor add myapp-ui ? 您是否真的使用meteor add myapp-ui将软件包添加到应用程序?

Try to depend on the templating package on the client and load client/dashboard.htm only on the client : 尝试依赖客户端上的templating包,并仅在客户端上加载client/dashboard.htm

api.use("templating", "client");
[...]
api.addFiles("client/dashboard.html", "client");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM