0

有没有办法从全局助手访问 Template 实例,反之亦然?

/lib/route.js(带有 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
});
4

1 回答 1

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

于 2014-11-15T02:46:14.910 回答