We have a number of modal dialogs. The Cancel/Save part of them is identical, so it would be good to factor that out to its own template.
But each dialog has a reactive variable on the template itself, controlling the active state of the Save button. There doesn’t seem to be any sane way to give the sub-template code access to this variable, making this refactoring impossible. Or am I missing something?
I’m primarily interested in if refactoring like this is doable in Meteor, but other ways of making this work are also interesting.
Concrete code:
<template name="modalA">
<div id="modalA" class="modal fade">
// content omitted
{{> cancelSave}}
</div>
</template>
Template.modalA.created = function() {
this.isSaveableReact = new ReactiveVar(false);
template.autorun(function() {
template.isSaveableReact.set(!!Template.currentData());
});
};
Template.cancelSave.helpers({
isSaveable: function() {
return Template.instance().parent().isSaveableReact.get(); // THIS IS IMPOSSIBLE
}
}