diff --git a/view/mustache/mustache.js b/view/mustache/mustache.js index 6780a32df1a..3fc5c098dd5 100644 --- a/view/mustache/mustache.js +++ b/view/mustache/mustache.js @@ -1866,9 +1866,10 @@ steal('can/util', * {{/unless}} */ 'unless': function (expr, options) { - if (!Mustache.resolve(expr)) { - return options.fn(options.contexts || this); - } + var fn = options.fn; + options.fn = options.inverse; + options.inverse = fn; + return Mustache._helpers['if'].fn.apply(this, arguments); }, // Implements the `each` built-in helper. diff --git a/view/mustache/mustache_test.js b/view/mustache/mustache_test.js index 194662f9f18..dc2fa36ab74 100644 --- a/view/mustache/mustache_test.js +++ b/view/mustache/mustache_test.js @@ -3789,4 +3789,10 @@ steal("can/model", "can/view/mustache", "can/test", "can/view/mustache/spec/spec .render({}, t.helpers), t.expected); }); + test("{{else}} with {{#unless}} (#988)", function(){ + var tmpl = "
{{#unless noData}}data{{else}}no data{{/unless}}
"; + + var frag = can.mustache(tmpl)({ noData: true }); + equal(frag.childNodes[0].innerHTML, 'no data', 'else with unless worked'); + }); }); diff --git a/view/stache/mustache_helpers.js b/view/stache/mustache_helpers.js index 424723e7e67..32b01f72e63 100644 --- a/view/stache/mustache_helpers.js +++ b/view/stache/mustache_helpers.js @@ -81,9 +81,10 @@ steal("can/util", "./utils.js","can/view/live",function(can, utils, live){ } }, 'unless': function (expr, options) { - if (!resolve(expr)) { - return options.fn(options.scope || this); - } + var fn = options.fn; + options.fn = options.inverse; + options.inverse = fn; + return helpers['if'].apply(this, arguments); }, 'with': function (expr, options) { var ctx = expr; diff --git a/view/stache/stache_test.js b/view/stache/stache_test.js index 965f39aecde..baabc4ac066 100644 --- a/view/stache/stache_test.js +++ b/view/stache/stache_test.js @@ -3460,4 +3460,11 @@ steal("can/view/stache", "can/view","can/test","can/view/mustache/spec/specs",fu frag = can.stache(t.template)({}, t.helpers); equal(frag.childNodes[0].nodeValue, t.expected); }); + + test("{{else}} with {{#unless}} (#988)", function(){ + var tmpl = "
{{#unless noData}}data{{else}}no data{{/unless}}
"; + + var frag = can.stache(tmpl)({ noData: true }); + equal(frag.childNodes[0].innerHTML, 'no data', 'else with unless worked'); + }); });