Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] render helper should defer to View when choosing template #10712

Merged
merged 1 commit into from
Mar 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/ember-routing-htmlbars/lib/helpers/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,19 @@ export function renderHelper(params, hash, options, env) {
name = name.replace(/\//g, '.');
// \ legacy slash as namespace support

var templateName = 'template:' + name;
Ember.assert(
"You used `{{render '" + name + "'}}`, but '" + name + "' can not be " +
"found as either a template or a view.",
container._registry.has("view:" + name) || container._registry.has(templateName) || !!options.template
);

view = container.lookup('view:' + name) || container.lookup('view:default');
var template = options.template;
view = container.lookup('view:' + name);
if (!view) {
view = container.lookup('view:default');
template = template || container.lookup(templateName);
}

// provide controller override
var controllerName;
Expand Down Expand Up @@ -174,14 +185,6 @@ export function renderHelper(params, hash, options, env) {

hash.viewName = camelize(name);

var templateName = 'template:' + name;
Ember.assert(
"You used `{{render '" + name + "'}}`, but '" + name + "' can not be " +
"found as either a template or a view.",
container._registry.has("view:" + name) || container._registry.has(templateName) || !!options.template
);
var template = options.template || container.lookup(templateName);

if (router && !initialContext) {
router._connectActiveView(name, view);
}
Expand Down
20 changes: 20 additions & 0 deletions packages/ember-routing-htmlbars/tests/helpers/render_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,23 @@ QUnit.test("throws an assertion if {{render}} is called with a literal for a mod
runAppend(view);
}, "The second argument of {{render}} must be a path, e.g. {{render \"post\" post}}.");
});

QUnit.test("{{render}} helper should let view provide its own template", function() {
var template = "{{render 'fish'}}";
var controller = EmberController.extend({ container: container });
view = EmberView.create({
controller: controller.create(),
template: compile(template)
});

container._registry.register('template:fish', compile('Hello fish!'));
container._registry.register('template:other', compile('Hello other!'));

container._registry.register('view:fish', EmberView.extend({
templateName: 'other'
}));

runAppend(view);

equal(view.$().text(), 'Hello other!');
});