Last active
March 24, 2022 16:32
-
-
Save amitkumar/b1969e86e1379db83511 to your computer and use it in GitHub Desktop.
Revisions
-
amitkumar revised this gist
Jul 30, 2014 . 2 changed files with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,3 +12,10 @@ <span class="first-friend-name">{{#array_item friends 0}}{{firstName}} {{lastName}}{{/array_item}}</span> </script> <script id="each_upto_example" type="text/x-handlebars-template"> <ul> {{#each_upto friends 3}} <li class="item item-{{@itemIndex}}"></li> {{/each_upto}} </ul> </script> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,26 @@ Handlebars.registerHelper('if_equals', function(conditional, value, options) { Handlebars.registerHelper('array_item', function(array, index, options) { return options.fn(array[index]); }); /** * @param ary {Array} * @param max {Number} The max number of items to display from the array * @param [options.skip] {Number=0} Optional. Number of items to skip in the array */ Handlebars.registerHelper('each_upto', function(ary, max, options) { if(!ary || ary.length == 0) return options.inverse(this); var result = [], skip = (options.hash ? (options.hash.skip ? options.hash.skip : 0) : 0), i = skip; max += skip; for(; i < max && i < ary.length; ++i) { result.push(options.fn(ary[i], { data : { itemIndex : i } } )); } return result.join(''); }); -
amitkumar created this gist
Jul 30, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <script id="if_equals_example" type="text/x-handlebars-template"> {{#if_equals objectType 'message'}} <div class="message"> Message </div> {{else}} {{/if_equals}} </script> <script id="array_item_example" type="text/x-handlebars-template"> <span class="first-friend-name">{{#array_item friends 0}}{{firstName}} {{lastName}}{{/array_item}}</span> </script> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ Handlebars.registerHelper('if_equals', function(conditional, value, options) { if (conditional === value){ return options.fn(this); } else { return options.inverse(this); } }); Handlebars.registerHelper('array_item', function(array, index, options) { return options.fn(array[index]); });