Skip to content

Instantly share code, notes, and snippets.

@wycats
Forked from swannodette/gist:1246024
Created September 27, 2011 21:42
Show Gist options
  • Save wycats/1246335 to your computer and use it in GitHub Desktop.
Save wycats/1246335 to your computer and use it in GitHub Desktop.
named_subtemplates.hb
<!--
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);
-->
/*
<!--
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