mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Allow our template partials to take additional named arguments
(imported from commit 20e7dae7b5d27ee34936d400394357fc31c8e628)
This commit is contained in:
committed by
Jessica McKellar
parent
409bc7b657
commit
865c57fa72
@@ -19,10 +19,21 @@ exports.render = function (name, arg) {
|
||||
// Furthermore, waiting for DOM ready would introduce race conditions with
|
||||
// other DOM-ready callbacks that attempt to render templates.
|
||||
|
||||
// Regular Handlebars partials require pre-registering. This allows us
|
||||
// to treat any template as a partial.
|
||||
Handlebars.registerHelper('partial', function (template_name, context) {
|
||||
return new Handlebars.SafeString(exports.render(template_name, this));
|
||||
// Regular Handlebars partials require pre-registering. This allows us to treat
|
||||
// any template as a partial. We also allow the partial to be passed additional
|
||||
// named arguments. Arguments should alternate between strings which will be
|
||||
// used as the name and the associated value.
|
||||
Handlebars.registerHelper('partial', function (template_name) {
|
||||
var extra_data = {};
|
||||
var args_len = arguments.length;
|
||||
var i;
|
||||
|
||||
for (i = 1; i < args_len - 2; i += 2) {
|
||||
extra_data[arguments[i]] = arguments[i + 1];
|
||||
}
|
||||
var data = _.extend({}, this, extra_data);
|
||||
|
||||
return new Handlebars.SafeString(exports.render(template_name, data));
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('plural', function (condition, one, other) {
|
||||
|
||||
Reference in New Issue
Block a user