0

Is there a way to gain access to the Template instance from a global helper and vice versa?

/lib/route.js (with Iron Router):

Router.route('/', {name: 'home.view', controller: 'homeController'});
homeController = RouteController.extend({
    template: 'home',
    waitOn: function () {
      Meteor.subscribe("Person", Meteor.userId());
    },
    data: function () {
        // return some data;
    }
});

homeController.helpers({
   templateInstanceHelper: function () {
      // Access a "global" helper here
   }
});

/client/helpers.js:

Template.helpers("globalHelper", function () {
   // Access the template instance helper here
});
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Aaron
  • 3,068
  • 2
  • 21
  • 44

1 Answers1

0

Have you considered defining a global method instead? Instead of registering with Meteor Templates, just define it as

globalHelperFunc = function(templateVar) {
   // do work
}

Note that this need to be in "lib" folder, so maybe (/lib/helpers.js)

Reference: Global function for Meteor template helper

Community
  • 1
  • 1
yifanwu
  • 1,595
  • 3
  • 14
  • 25
  • Thanks. But I need access to the Template instance "Person" subscription data. I need, for example, the count of the "Person" collection, I need the actual record in some cases, and I need to assign the "Person" record to a #with context within the Template itself. – Aaron Nov 15 '14 at 17:42