meteormeteor-helpertelescope

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


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.


Solution

  • Your package load order is wrong, you must load the template declaration (html) before the template helpers declaration (js), you just need to swap your api.addFiles calls.

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