I need to dynamically create a copy of a template in Meteor. The copy should have the same handlebars content, but a different set of helpers, methods and event handlers. How can I achieve that?
I've tried:
Template.copy = function() {
return Template.original.apply(this, arguments);
}
and it displays the right html, but the resulting template is not reactive. On the other hand, when I do
Template.copy = function() {
return Meteor.render(Template.original.apply(this, arguments));
}
the result of render is a DocumentFragment object that I don't know how to properly convert to string or attach to DOM.
I guess this package should work fine. Basically speaking, to achieve what you want, you need to get access to your tempalte's raw_func and then call Template.__define__(name, raw_func) with a different name. It is possible to do that, if you hack the original Template.__define__, as it is done here). However, you'll need a package to do all the hacking in the right moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With