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

时间:2015-09-22 19:47:49

标签: meteor meteor-helper telescope

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

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,存在于同一目录下的同一个包中。我通过使用全局辅助方法解决了这个问题,但这是一个低效的修复方法。

1 个答案:

答案 0 :(得分:1)

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

api.addFiles('lib/client/lightbox.html', 'client');
api.addFiles('lib/client/lightBox.js', 'client');
相关问题