title: Ember.js and handlebars each helper, with subviews
body: <p>I'm triyng to use the view helper inside my {{#each}} template blocks without using global paths (my controllers create and destroy their own views).</p>
  
  <p>Examples. Given a view with a myList array property, and an itemButton child view:</p>
  
  <p>This will work</p>
  
  <pre><code>&lt;script type="text/x-handlebars" name="my-list-view"&gt;
  {{#each myList}} &lt;!-- App.myListView.myList --&gt;
  
      {{view App.myListView.itemButton}} {{title}}
  
  {{/each}}
  &lt;/script&gt;
  </code></pre>
  
  <p><br />
    This will not:</p>
  
  <pre><code>&lt;script type="text/x-handlebars" name="my-list-view"&gt;
  {{itemButton}} &lt;!-- works fine outside the each --&gt;
  {{#each myList}}
  
      {{view itemButton}} {{title}} &lt;!-- itemButton view not found --&gt;
  
  {{/each}}
  &lt;/script&gt;
  </code></pre>
  
  <p>I do not appear to be able to access the parent view from the each view helper (or in fact access anything other than the properties of the objects being iterated).</p>
  
  <p><strong>The hacky workarounds</strong> I've come up with are:</p>
  
  <ul>
  <li>Add the view I want to use to the items I'm iterating over.</li>
  </ul>
  
  <p>or</p>
  
  <ol>
  <li>Creating a collectionView in App.myListView </li>
  <li>Create an itemViewClass view in that collection view class</li>
  <li>Move the itemButton view inside the itemViewClass</li>
  <li>Replace {{#each}} with {{#collection}}</li>
  </ol>
  
  <p>or</p>
  
  <ul>
  <li>Create a custom handlebars helper for iteration.</li>
  </ul>
  
  <p>Both of these options seem horrible.
  Surely there's a better alternative than creating 2 new classes (and nesting 4 views deep) just to iterate over a list, though. Is there a replacement handlebars helper I can use instead?</p>
  
  <hr>
  
  <h1>Workaround implementations</h1>
  
  <h2>Option #1 : Modifing the content array</h2>
  
  <p><a href="http://jsfiddle.net/FQEZq/3/" rel="nofollow">http://jsfiddle.net/FQEZq/3/</a>
  Disadvantages: Having to add the view to each model instance just for iteration.</p>
  
  <h2>Option #2 : Custom collection view</h2>
  
  <p><a href="http://jsfiddle.net/ST24Y/1/" rel="nofollow">http://jsfiddle.net/ST24Y/1/</a>
  Disadvantages: Now you have two additional views that you do not need / want,  and less control of markup. References from the child view to the parent instance now requires parentView.parentView.parentView.</p>