-
-
Save wycats/1246335 to your computer and use it in GitHub Desktop.
named_subtemplates.hb
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 characters
<!-- | |
I'm sure there's a better syntax for naming subtemplates | |
--> | |
<h3>This is a list</h3> | |
<ul> | |
{{#each items}} | |
{{@cell}} | |
<li> | |
{{..}} | |
</li> | |
{{/cell}} | |
{{/each}} | |
</ul> | |
<!-- | |
var template = Handlebars.compile(...); | |
. | |
. | |
. | |
template(items); | |
template.cell(item); | |
--> |
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 characters
/* | |
<!-- | |
I'm sure there's a better syntax for naming subtemplates | |
--> | |
<h3>This is a list</h3> | |
<ul> | |
{{#each items}} | |
{{#named "cell"}} | |
<li> | |
{{..}} | |
</li> | |
{{/named}} | |
{{/each}} | |
</ul> | |
*/ | |
Handlebars.registerHelper('named', function(name, options) { | |
options.data.named[name] = options.fn; | |
}); | |
var template = Handlebars.compile(..., { data: true }); | |
var named = {}; | |
template(items, { data: { named: named } }); | |
named.cell(item); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment