qobayishi
qobayishi

Reputation: 35

How is it possible to call function from different templates in blazeComponent?

I want to call a method from different template, for example:

class studens extends BlazeComponent {
    average() {}
}
studens.register("templatestudens");

class teacher extends BlazeComponent {
    // how to call templatestudens 'average' function from here?
}
teacher.register("templateteacher");

Upvotes: 0

Views: 71

Answers (1)

Ankur Soni
Ankur Soni

Reputation: 6008

I would recommend you to define methods in global register helper. Then you can call that method from any template as below;

CODE for Global declaration for method:

Template.registerHelper("average", function(){
  //code here
});

CODE to call the global helper (in js file) method from any template

Template.YOUR_TEMPLATE.helpers({
  getAverage(){
    return Blaze._globalHelpers['average']();
  }
});

I hope this helps.

Upvotes: 1

Related Questions