I\'m definitely missing something about the way Handlebars works. I need to call different partials depending on the value of a variable. Currently the only way I\'ve found to d
The partials are stored in Handlebars.partials
so you can access them by hand in your own helper. There are a few tricky bits here though:
Handlebars.partials
can be strings or functions so you have to compile the partials on first use.text/plain
or text/html
so you'll need to call your helper in {{{...}}}
or {{...}}
as appropriate.console.log(arguments)
to figure out how to use Handlebars.partials
.this
by hand when you call the helper.Fear not, it isn't really that complicated. Something simple like this:
Handlebars.registerHelper('partial', function(name, ctx, hash) {
var ps = Handlebars.partials;
if(typeof ps[name] !== 'function')
ps[name] = Handlebars.compile(ps[name]);
return ps[name](ctx, hash);
});
should do the trick. Then you can say:
{{{partial mode this}}}
and get on with more interesting things.
Demo: http://jsfiddle.net/ambiguous/YwNJ3/2/