Skip to content

Commit

Permalink
Allow extending lookup for templates as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Mar 28, 2015
1 parent c8212d0 commit 93eb5c3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/blaze/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ var wrapHelper = function (f, templateFunc) {
};
};

Blaze._getTemplate = function (name) {
if (name in Blaze.Template) {
return Blaze.Template[name];
}
return null;
};

// Looks up a name, like "foo" or "..", as a helper of the
// current template; a global helper; the name of a template;
// or a property of the data context. Called on the View of
Expand All @@ -94,6 +101,7 @@ Blaze.View.prototype.lookup = function (name, _options) {
var lookupTemplate = _options && _options.template;
var helper;
var boundTmplInstance;
var foundTemplate;

if (this.templateInstance) {
boundTmplInstance = _.bind(this.templateInstance, this);
Expand All @@ -110,9 +118,9 @@ Blaze.View.prototype.lookup = function (name, _options) {
} else if (template &&
((helper = Blaze._getTemplateHelper(template, name, templateInstance)) != null)) {
return wrapHelper(bindDataContext(helper), boundTmplInstance);
} else if (lookupTemplate && (name in Blaze.Template) &&
(Blaze.Template[name] instanceof Blaze.Template)) {
return Blaze.Template[name];
} else if (lookupTemplate && (foundTemplate = Blaze._getTemplate(name)) &&
(foundTemplate instanceof Blaze.Template)) {
return foundTemplate;
} else if (Blaze._globalHelpers[name] != null) {
return wrapHelper(bindDataContext(Blaze._globalHelpers[name]),
boundTmplInstance);
Expand Down

0 comments on commit 93eb5c3

Please sign in to comment.