Helper Data
Example of working with options.data attribute in a block helper
by Christopher McCulloh
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.js"></script>
<script id="basic-template-helper" type="text/x-handlebars-template">
<p>Preserve context:
{{#dataExample}}
{{@index}}
{{/dataExample}}
</p>
</script>
<dl id="target"></dl>
JavaScript
Handlebars.registerHelper('dataExample', function (options) {
});
var context = {
doctors: [‘Hartnell’,‘Troughton’,‘Pertwee’,‘Baker’,‘Davison’,‘Baker’,‘McCoy’,‘McGann’,‘Eccleston’,‘Tennant’,‘Smith’,‘Capaldi’]
};
var template = Handlebars.compile($('#basic-template-helper').html());
$('#target').append(template(context));