Fix UI.contentBlock data context

This commit is contained in:
David Greenspan
2014-07-01 10:25:48 -07:00
parent 8c8887da7c
commit 284529992e
2 changed files with 12 additions and 3 deletions

View File

@@ -617,8 +617,17 @@ Blaze.Each = function (argFunc, contentFunc, elseFunc) {
return eachView;
};
Blaze.SetParentView = function (parentView, contentFunc) {
var view = Blaze.View('SetParentView', contentFunc);
Blaze.InOuterTemplateScope = function (templateView, contentFunc) {
var view = Blaze.View('InOuterTemplateScope', contentFunc);
var parentView = templateView.parentView;
// Hack so that if you call `{{> foo bar}}` and it expands into
// `{{#with bar}}{{> foo}}{{/with}}`, and then `foo` is a template
// that inserts `{{> UI.contentBlock}}`, the data context for
// `UI.contentBlock` is not `bar` but the one enclosing that.
if (parentView.__isTemplateWith)
parentView = parentView.parentView;
view.onCreated(function () {
this.parentView = parentView;
});

View File

@@ -133,7 +133,7 @@ _.extend(CodeGen.prototype, {
if (path[0] === 'UI' &&
(path[1] === 'contentBlock' || path[1] === 'elseBlock')) {
includeCode = 'Blaze.SetParentView(view, function () { return '
includeCode = 'Blaze.InOuterTemplateScope(view, function () { return '
+ includeCode + '; })';
}