diff --git a/packages/handlebars/evaluate.js b/packages/handlebars/evaluate.js
index 1accbc99c0..31403fd1a7 100644
--- a/packages/handlebars/evaluate.js
+++ b/packages/handlebars/evaluate.js
@@ -28,7 +28,10 @@ Handlebars.json_ast_to_func = function (ast) {
// what is passed in via named arguments.
Handlebars._default_helpers = {
'with': function (data, options) {
- return options.fn(data);
+ if (!data || (data instanceof Array && !data.length))
+ return options.inverse(this);
+ else
+ return options.fn(data);
},
'each': function (data, options) {
var parentData = this;
diff --git a/packages/templating/templating_tests.html b/packages/templating/templating_tests.html
index 2ad6fae73a..fd7a4cd577 100644
--- a/packages/templating/templating_tests.html
+++ b/packages/templating/templating_tests.html
@@ -355,3 +355,11 @@
{{#each values}}{{this}}{{/each}}
+
+
+
+{{# with value1}}{{this}}{{else}}xxx{{/with}}
+{{# with value2}}{{this}}{{else}}xxx{{/with}}
+{{# with value1}}{{this}}{{/with}}
+{{# with value2}}{{this}}{{/with}}
+
diff --git a/packages/templating/templating_tests.js b/packages/templating/templating_tests.js
index 40ad9dc4cc..70a5fbc839 100644
--- a/packages/templating/templating_tests.js
+++ b/packages/templating/templating_tests.js
@@ -1092,3 +1092,10 @@ Tinytest.add('templating - each falsy Issue #801', function (test) {
var frag = Meteor.render(Template.test_template_issue801);
test.equal(canonicalizeHtml(DomUtils.fragmentToHtml(frag)), "12null");
});
+
+Tinytest.add('templating - with falsy Issue #770', function (test) {
+ Template.test_template_issue770.value1 = function () { return "abc"; };
+ Template.test_template_issue770.value2 = function () { return false; };
+ var frag = Meteor.render(Template.test_template_issue770);
+ test.equal(canonicalizeHtml(DomUtils.fragmentToHtml(frag)), "abcxxxabc");
+});
\ No newline at end of file