Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking #each loop in handlebar

I am having a handlebar script code like this inside my ascx file.

<script id="ex" type="text/x-handlebars-template">
 {{#each model}}
   {{#if condition}}
  //Need to Break, Dont know how to do that
   {{/if}}
 {{/each}}
</script>
like image 733
Venkatesh K Avatar asked Feb 17 '14 10:02

Venkatesh K


1 Answers

Just pass this object it to a javascript function, do the required logic and return it.

<script type= "text/javascript">
    Handlebars.registerHelper("ifSet", function (model) {        
        var count = 0;
        while (count < model.length) {            
    //    if (logic Condition){
    //      return 'Success';  or Break;             
    //    }
        }
        return;
    });     
</script>

<script id="ex" type="text/x-handlebars-template">
 {{ifSet model}}
</script>
like image 190
Venkatesh K Avatar answered Sep 22 '22 01:09

Venkatesh K