MeteorCommunity/discussions

Impossible to copy helpers between templates

mitar opened this issue · 5 comments

Previously, I could do:

Template.searchInput.indexHeader = Template.header.indexHeader;

Template.searchInput.noIndexHeader = Template.header.noIndexHeader;

Now this is not anymore possible, because helpers are not exposed easily. This makes code reusability harder.

raix commented

Thats a good point now you would have to declare these in a scope and add them as helpers. Does Template.foo.helpers() extend the helpers or set the helpers?

Or maybe we are in general missing some extendable way to extend/mixin templates.

Can you share helpers as @raix suggested?

var myHelper = function () {
...
}

Template.foo.helpers({
  helper1: myHelper,
  ...
}

Template.bar.helpers({
  baz: myHelper,
  ...
}

The point is that the template might be implemented in 3rd party package and you do not have access to the function otherwise.

After some testing, I think meteor-template-extension is a good candidate to declare this issue solved. It really does the job.