title: Handlebars Block Helper : each with sort
body: <p>I have an array of json objects which I output using a Handlebars template; I am currently doing using {{#each object}}...{{/each}}.  I now need to sort the objects by one of the object's properties, which again is no problem using a handlebars helper &amp; coffeescript, however, I have a problem in my template in that I cannot work out how to iterate over the sorted array using each.</p>
  
  <p>My research so far indicates that I probably need to write a custom Handlebars helper which will, in effect, be:</p>
  
  <pre><code>{{#each_with_sort array}}
  </code></pre>
  
  <p>My existing sort helper is like this</p>
  
  <pre><code>   Handlebars.registerHelper sort_me =&gt;
       myArray.sort (a,b)-&gt;
         return if +a.sort_index &gt;= +b.sort_index then 1 else -1
  </code></pre>
  
  <p>but, I am struggling to be able to use the sorted array in the template - for example, it is not as simple as </p>
  
  <pre><code> {{#each sort_me(myArray)}}
  </code></pre>
  
  <p>The data is coming from a third party API, so I have to perform sorting in handlebars/coffeescript.</p>