1

I have been able to insert this template titled lightBox using Telescope.modules.add The file structure seems to be working fine except I cannot make a template helper to interact with the template thats inserted using Telescope.modules.add function. The following code produces a client side error of "Uncaught TypeError: Cannot read property 'helpers' of undefined". Without this helper method the template is visible and does exist in the browser view.

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');
});

Template is named lightBox and exists in the same package within the same directory. I have worked around this by using a global helper methods but this is an inefficient fix.

4

1 回答 1

1

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

api.addFiles('lib/client/lightbox.html', 'client');
api.addFiles('lib/client/lightBox.js', 'client');
于 2015-09-22T19:55:04.137 回答