title: Handlebars.js each helper with if condition
body: <p>I am using the below helper to iterate through a JSON array and return a result based on the condition to find whether an Account is closed or not (<code>OpenOrClosedDesc=='Closed'</code>). I am getting all of the Accounts that are closed. But now I want to print an error message on the screen if there are no Closed Accounts.</p>
  
  <pre><code>Handlebars.registerHelper('each_Closed', function(list, opts) {
                  var i, result = '';
                  try {
                      //console.log("List Closed length "+ list.length)
                      for (i = 0; i &lt; list.length; i++)
                          if (list[i].OpenOrClosedDesc == 'Closed'){
                            //  console.log("List Closed  "+ list[i].OpenOrClosedDesc == 'Closed')
                              result = result + opts.fn(list[i]);
                          }
                  return result;
              }catch(e){
  
              }
          });
  </code></pre>
  
  <p>HTML Code :</p>
  
  <pre><code>&lt;div id = "Revolving_ClosedAcc"&gt;
     {{#repData}}
       {{#each_Closed arf.TradeLine.TradeLine.[Revolving Accounts]}}
      .
      .
      .
      .
      .
      {{/each_Closed}}
    {{/repData}}
  &lt;/div&gt;
  </code></pre>
  
  <p>EDIT Explanation for possible duplicate: 
  I tried to return the error message from an else branch but it did not give accurate results. It simply shows there are no closed accounts if it finds one of the accounts is closed. It doesn't go through the for loop. The for loop is the main path as I want to iterate through the whole object array.</p>
  
  <p>EDIT for having count of each account: </p>
  
  <pre><code>Handlebars.registerHelper('each_Closed', function(list, opts) {
                  var i, result = '',resCounter=0,closedAccountFound = false;
                  try {
                      //console.log("List Closed length "+ list.length)
                      for (i = 0; i &lt; list.length; i++) {
                          if (list[i].OpenOrClosedDesc == 'Closed') {
                              // console.log("List Closed  "+ list[i].OpenOrClosedDesc == 'Closed')
                              result = result + opts.fn(list[i]);
                              resCounter++;
                              closedAccountFound = true;
                          }
                      }
                      console.log(resCounter);
                      return closedAccountFound ? result : "No close account found.";
                  }catch(e){
  
                  }
              });
  </code></pre>
  
  <p>I am getting count in console.log(resCounter) 
  but how can i return that or in other words how i can print that in handlebars ? 
  Do i have to write another helper ? </p>
  
  <p>How can i do that?</p>
  
  <p>Thanks in advance.</p>