首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Template.helpers访问Template.TemplateName.helpers,反之亦然

从Template.helpers访问Template.TemplateName.helpers,反之亦然
EN

Stack Overflow用户
提问于 2014-11-15 10:27:54
回答 1查看 118关注 0票数 0

有没有办法从全局帮助器访问模板实例,反之亦然?

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

代码语言:javascript
复制
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:

代码语言:javascript
复制
Template.helpers("globalHelper", function () {
   // Access the template instance helper here
});
EN

回答 1

Stack Overflow用户

发布于 2014-11-15 10:46:15

您是否考虑过改为定义一个全局方法?不用注册Meteor模板,只需将其定义为

代码语言:javascript
复制
globalHelperFunc = function(templateVar) {
   // do work
}

注意,这需要在"lib“文件夹中,所以可能(/lib/helpers.js)

参考:Global function for Meteor template helper

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26941847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档