In many templates I want to use the same functions, but they must defined in every template. like this:
function getNodesById(id){
return collection.find({sid:id}).fetch();
}
Template.navigation.getNodesById= function(id){
return getNodesById(id);
}
Template.body.getNodesById= function(id){
return getNodesById(id);
}
Html:
<Template name="navigation"> ... {{#each getNodesById '1'}} ... {{/each}} ... </Template> <Template name="body"> ... {{#each getNodesById '1'}} ... {{/each}} ... </Template> ... <Template name="..."> ..... </Template>
Are There any way can defined globle template function instead of a template ? just like it: In javascript:
defined global tempele.functionA = function(...){ return ... }
in html:
<Template name ="a"> {{#each functionA ...}} {{/each }} </Template> <Template name ="b"> {{#each functionA ...}} {{/each }} </Template> <Template name="..."> {{ #.. functionA ...}} .... {{/...}} </Template >
Can I do this? I hope I described the problem clearly.