Handlebars.js - Global Contexts
Say I have a static list of users cached somewhere in my application like
App.Users. I'll probably have the need to list my users in several dozen
places in my application. Conventionally, I'll just need to pass my list
in with my context to the template.
var tmpl = Handlebars.templates['TemplateName'];
var html = tmpl({
model: model,
users: App.Users
});
But this approach requires some wiring in both the template and the
javascript. What I would like to do is specify this in the template alone
so I don't need to remember this in my scripts. Consider something like
this...
{{#each {{users}}}}
<li> ... </li>
{{/each}}
...Where users is a helper function that just returns my App.Users.
Wouldn't that be nice?
So that totally doesn't compile. What is another solution?
No comments:
Post a Comment