title: Reuse Meteor template as inclusion with different helpers
body: <p>I'd like to re-use a Meteor template as an inclusion (i.e. using <code>{{&gt; }}</code>) in two different contexts. I know I can pass in different data with the inclusion by using <code>{{&gt; templateName data1=foo data2=bar}}</code>, but I'm struggling to figure out how I can provide different helpers based on the context. Here's the template in question:</p>
  
  <pre><code>&lt;template name="choiceQuestion"&gt;
    &lt;div class="choice-grid" data-picks="{{numberOfPicks}}" data-toggle="buttons"&gt;
      {{! Provide for the user to make multiple selections from the multiple choice list }}
      {{#if hasMultiplePicks}}
        {{#unless canPickAll}}&lt;span class="help-block text-center"&gt;Pick up to {{numberOfPicks}}&lt;/span&gt;{{/unless}}
        {{#each choices}}
          &lt;label class="btn btn-default"&gt;&lt;input type="checkbox" class="choice" name="{{this}}" autocomplete="off" value="{{this}}" checked="{{isChecked}}"&gt; {{this}}&lt;/label&gt;
        {{/each}}
      {{/if}}{{! hasMultiplePicks}}
      {{#if hasSinglePick}}
        {{#each choices}}
          &lt;label class="btn btn-default"&gt;&lt;input type="radio" class="choice" name="{{this}}" id="{{this}}" autocomplete="off" value="{{this}}" checked="{{isChecked}}"&gt; {{this}}&lt;/label&gt;
        {{/each}}
      {{/if}}{{! hasSinglePick}}
    &lt;/div&gt;
  &lt;/template&gt;
  </code></pre>
  
  <p>and here's how I've reused it:</p>
  
  <pre><code>{{&gt; choiceQuestion choices=allInterests picks=4}}
  </code></pre>
  
  <p>The key component of the template is a checkbox. In one context, it will never be checked. In another, it may be checked based on the contents of a field in the user document. I've added <code>checked={{isChecked}}</code> to the template. I've read this boolean attribute will be omitted if a falsey value is returned from the helper which should work well for my purposes.</p>
  
  <p>The template's JS intentionally does <em>not</em> have an <code>isChecked</code> helper. I had hoped I could provide one on the parent where the template is included in the other context in order to conditionally check the box by returning true if the checked conditions are met, but the template doesn't acknowledge this helper.</p>
  
  <p>Here's the template's JS:</p>
  
  <pre><code>Template.choiceQuestion.helpers({
    hasSinglePick: function() {
      return this.picks === 1;
    },
    hasMultiplePicks: function() {
      return this.picks &gt; 1 || !this.picks;
    },
    numberOfPicks: function() {
      return this.picks || this.choices.length;
    },
    canPickAll: function() {
      return !this.picks;
    },
  });
  </code></pre>
  
  <p>and the parent's JS:</p>
  
  <pre><code>Template.dashboard.helpers({
    postsCount: function() {
      var count = (Meteor.user().profile.posts||{}).length;
      if (count &gt; 0) {
        return count;
      } else {
        return 0;
      }
    },
    isChecked: function() {
        return (((Meteor.user() || {}).profile || {}).contentWellTags || []).indexOf(this) &gt; -1 ? 'checked' : null;
    }
  });
  
  Template.dashboard.events({
    'click .js-your-profile-tab': function(){
      facebookUtils.getPagesAssumeLinked();
    }
  });
  </code></pre>
  
  <p>I've tried a few other approaches as well. I tried passing the helper to the template along with the other context (i.e. <code>{{&gt; templateName data1=foo data2=bar isChecked=isChecked}}</code>. This kinda works, but it calls the helper immediately. This breaks these since I need to use a value from the context to determine what to return from my helper. Since this value doesn't exist when the function returns, the function always returns undefined.</p>
  
  <p>If I return a function from this helper rather than the value and then pass the helper into the template inclusion along with the data context, I get better results. In fact, my console logs show the desired output, but I still don't end up with the checked box I expect.</p>
  
  <p>Here's what that looks like. Returning a function:</p>
  
  <pre><code>  isChecked: function() {
        var self = this;
        return function() {
            return (((Meteor.user() || {}).profile || {}).contentWellTags || []).indexOf(this) &gt; -1 ? 'checked' : null;
        };
    }
  </code></pre>
  
  <p>and passing that to the template:</p>
  
  <pre><code>{{&gt; choiceQuestion choices=allInterests picks=4 isChecked=isChecked}}
  </code></pre>
  
  <p>Is there an established pattern for overriding template helpers from the parent or for including helpers on the parent that are missing from the child template? How can I achieve this?</p>