使用 Telescope.modules.add 时 Telescope 包中的模板助手

Template helpers in Telescope Package when using Telescope.modules.add

我已经能够使用 Telescope.modules.add 插入这个名为 lightBox 的模板 文件结构似乎工作正常,除了我无法制作模板助手来与使用 Telescope.modules.add 函数插入的模板进行交互。以下代码产生 "Uncaught TypeError: Cannot read property 'helpers' of undefined" 的客户端错误。如果没有这个辅助方法,模板是可见的,并且确实存在于浏览器视图中。

lightBox.js

if (Meteor.isClient) {
  Telescope.modules.add("top", {
    template: "lightBox",
    order: 0
  });

  Template.layout.events({
    'click .post-content': function (e) {
      Session.set('lightBoxPageViewCounter', 1 );
    }
  });

  Template.lightBox.helpers({
    lightBoxOn: function() {
      return true;
    }
  });
}

Package.js

Package.describe({
  name: "admithub:admithub-lightbox",
  summary: "popup lightbox for admit hub forum to college email leads",
  version: "0.0.1"
});

Package.onUse(function(api) {
  api.use([
    'accounts-base',
    'stylus',
    'telescope:core@0.24.0',
    'aldeed:simple-schema',
    'aldeed:collection2',
    'aldeed:autoform'
  ]);

  api.addFiles('lib/client/lightBox.js', 'client');
  api.addFiles('lib/client/lightbox.html', 'client');
  api.addFiles('lib/client/lightbox.styl', 'client');
});

模板名为lightBox,存在于同一目录下的同一包中。我已经通过使用全局辅助方法解决了这个问题,但这是一个低效的修复方法。

你的包加载顺序错误,你必须在模板助手声明 (js) 之前加载模板声明 (html),你只需要交换你的 api.addFiles 调用。

api.addFiles('lib/client/lightbox.html', 'client');
api.addFiles('lib/client/lightBox.js', 'client');