lookup searches up for "data" arg

try `{{> content}}` instead of `body`
This commit is contained in:
David Greenspan
2013-06-25 12:13:42 -07:00
parent 62fb1f4bf2
commit ae295659d0
2 changed files with 25 additions and 6 deletions

View File

@@ -7,7 +7,9 @@
<h1>Hello {{name}}</h1>
{{#each items}}
<div>{{text}}</div>
{{#divwrap}}
<div>{{text}}</div>
{{/divwrap}}
{{else}}
<strong>Empty</strong>
{{/each}}
@@ -17,5 +19,9 @@
</body>
<template name="twice">
{{> body foo=123}} {{{middle}}} {{> body foo=456}}
{{> content foo=123}} {{{middle}}} {{> content foo=456}}
</template>
<template name="divwrap">
<div>{{> content}}</div>
</template>

View File

@@ -516,7 +516,6 @@ _.extend(Component.prototype, {
var result = null;
var thisToBind = null;
var data;
// XXX figure out what this should really do,
// and how custom component classes should
@@ -531,14 +530,28 @@ _.extend(Component.prototype, {
result = If;
} else if (id === 'each') {
result = Each;
} else if (id === 'content') {
return self.lookup('body'); // XXX hack for trying `content`
} else if (id in global) {
result = global[id];
thisToBind = self.getArg('data') || null;
} else if ((result = self.getArg(id))) {
thisToBind = self;
} else if ((data = self.getArg('data'))) {
thisToBind = data;
result = data[id];
} else {
// look for data arg, maybe in parent. stop as
// soon as we find a non-null value.
var comp = self;
var data = self.getArg('data');
// `== null` means null or undefined
while (data == null && comp.parent) {
comp = comp.parent;
data = comp.getArg('data');
}
if (data != null) {
thisToBind = data;
result = data[id];
}
}
if (thisToBind &&