title: handlebarjs block helper function (simple odd even attribute to add on each row of array) with requirejs
body: <p>I included handlebarjs on my requirejs backbone app and I wanted to implement a row class helper definition (odd|even) on templates, </p>
  
  <p>I'm trying to 'port' the native handlebar helper to a module based(requirejs): 
  <a href="http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers" rel="nofollow">http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers</a></p>
  
  <p>with handlebarjs plugin for requirejs:
  <a href="https://github.com/SlexAxton/require-handlebars-plugin" rel="nofollow">https://github.com/SlexAxton/require-handlebars-plugin</a></p>
  
  <p>Here is the one i got so far <strong>oddevenhelper.js</strong>: </p>
  
  <pre><code>define(['handlebars'], function ( Handlebars ){
    function oddevenhelper(array, even, odd, fn, elseFn) {
        if (array &amp;&amp; array.length &gt; 0) {
          var buffer = "";
          for (var i = 0, j = array.length; i &lt; j; i++) {
              var item = array[i];
  
              // we'll just put the appropriate stripe class name onto the item for now
              item.stripeClass = (i % 2 == 0 ? even : odd);
  
              // show the inside of the block
              buffer += fn(item);
          }
  
          // return the finished buffer
          return buffer;
        } else {
          return elseFn();
        }
    };
  
    Handlebars.registerHelper( 'oddevenhelper', oddevenhelper );
    return oddevenhelper;
  });
  </code></pre>
  
  <p>and this is my sample template:</p>
  
  <pre><code>&lt;div class="orderssummary-list"&gt;
          {{#oddevenhelper orderssummary "even" "odd"}}
              &lt;div class="ordersummary-list-item {{stripeClass}}"&gt;
                  &lt;a class="addone"&gt;&lt;i class="icon-chevron-up icon-white"&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;a class="minusone"&gt;&lt;i class="icon-chevron-down icon-white"&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;div class="item-quantity"&gt;{{quantity}}x&lt;/div&gt;&lt;div class="item-name"&gt;{{item_name}}&lt;/div&gt; {{total}}
                  &lt;div class="clearfix"&gt;
              &lt;/div&gt;
          {{/oddevenhelper}}
      &lt;/div&gt;
  </code></pre>
  
  <p>The helper runs, but handlebar throws error on, i guess on the 3rd  or 4th parameter which i declared on the template to be undefined or none at all.</p>
  
  <p>Am i missing something on this? Or i just let the context(orderssummary) to be redefined to include row classes? </p>