4 ms·
It's worth noting that #if, #each etc. are not built-in structures. They are simply helpers that you can register in the host language. Block helpers receive th
by wycats 15y ago
It's worth noting that #if, #each etc. are not built-in structures. They are simply helpers that you can register in the host language. Block helpers receive the block as a function that can be invoked as though it was a top-level template.
Consider the simple #with helper:
Handlebars.registerHelper('with', function(object, options) {
// invoke the sub-template passed as a block to the with helper with the object parameter
return options.fn(object);
});
And its usage:
{{#with person}}
Name: {{name}}
{{/with}}
This means that you can build arbitrary control structures and iterators in the host language and expose them to Handlebars.