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] {{#with}} helper should not render if passed variable is falsey #11035

Merged
merged 1 commit into from
May 7, 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
35 changes: 19 additions & 16 deletions packages/ember-htmlbars/lib/helpers/with.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import normalizeSelf from "ember-htmlbars/utils/normalize-self";
import shouldDisplay from "ember-views/streams/should_display";

/**
Use the `{{with}}` helper when you want to aliases the to a new name. It's helpful
Expand Down Expand Up @@ -44,24 +45,26 @@ import normalizeSelf from "ember-htmlbars/utils/normalize-self";
*/

export default function withHelper(params, hash, options) {
var preserveContext = false;
if (shouldDisplay(params[0])) {
var preserveContext = false;

if (options.template.arity !== 0) {
preserveContext = true;
}

if (preserveContext) {
this.yield([params[0]]);
} else {
let self = normalizeSelf(params[0]);
if (hash.controller) {
self = {
hasBoundController: true,
controller: hash.controller,
self: self
};
if (options.template.arity !== 0) {
preserveContext = true;
}

this.yield([], self);
if (preserveContext) {
this.yield([params[0]]);
} else {
let self = normalizeSelf(params[0]);
if (hash.controller) {
self = {
hasBoundController: true,
controller: hash.controller,
self: self
};
}

this.yield([], self);
}
}
}
11 changes: 11 additions & 0 deletions packages/ember-htmlbars/tests/helpers/with_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,14 @@ QUnit.test("nested {{with}} blocks shadow the outer scoped variable properly.",
runAppend(view);
equal(view.$().text(), "Limbo-Wrath-Treachery-Wrath-Limbo", "should be properly scoped after updating");
});

QUnit.test("{{with}} block should not render if passed variable is falsey", function () {
view = EmberView.create({
template: compile("{{#with foo as |bar|}}Don't render me{{/with}}"),
context: {
foo: null
}
});
runAppend(view);
equal(view.$().text(), "", "should not render the inner template");
});