"eachInObjectList" Handlebars Helper

Ein einfacher Handlebars.js Helper um durch ein assoziatives Array (Object) zu iterieren.

Handlebars Helper:
Handlebars.registerHelper('eachInObjectList', function(items, options) {  
    var output = '',
        data;
    for(var key in items) {
        data = Handlebars.createFrame(options.data || {});
        data.key = key;
        output = output + options.fn(items[key], {data:data});
    }
    return output;
});
Template Data:
var data = {  
        title:'Available Hours',
        hours:{
            'sunrise_06:00_am':'6 AM',
            'sunset_08:00_pm':'8 PM',
            'specific_identifier':'specific value'
        }
    }
Template:
<script id="tpl" type="text/x-handlebars-template">  
    <p>{{title}}</p>
    <ul>
    {{#eachInObjectList hours}}
        <li>{{@key}}: {{this}}</li>
    {{/eachInObjectList}}
    </ul>
</script>  
CodePen

Marco

daddy in love, runner, kiter, engineer, berlin, sheeeeeit!