Skip to content

Commit

Permalink
Handle empty responses from partials
Browse files Browse the repository at this point in the history
Fixes #675
  • Loading branch information
kpdecker committed Dec 23, 2013
1 parent 23d41e5 commit 93fb25c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function template(templateSpec, env) {
// TODO : Check this for all inputs and the options handling (partial flag, etc). This feels
// like there should be a common exec path
var result = invokePartial.apply(this, arguments);
if (result) { return result; }
if (result != null) { return result; }

var options = { helpers: helpers, partials: partials, data: data };
partials[name] = env.compile(partial, { data: data !== undefined }, env);
Expand All @@ -42,7 +42,7 @@ export function template(templateSpec, env) {
} else {
invokePartialWrapper = function(partial, name /* , context, helpers, partials, data */) {
var result = invokePartial.apply(this, arguments);
if (result) { return result; }
if (result != null) { return result; }
throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
};
}
Expand Down
6 changes: 6 additions & 0 deletions spec/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ describe('partials', function() {
var hash = {name:"Jeepers", another_dude:"Creepers"};
shouldCompileToWithPartials(string, [hash, {}, {'+404/asdf?.bar':dude}], true, "Dudes: Jeepers", "Partials can use literal paths");
});

it('should handle empty partial', function() {
var string = "Dudes: {{#dudes}}{{> dude}}{{/dudes}}";
var partial = "";
var hash = {dudes: [{name: "Yehuda", url: "http://yehuda"}, {name: "Alan", url: "http://alan"}]};
shouldCompileToWithPartials(string, [hash, {}, {dude: partial}], true, "Dudes: "); });
});

0 comments on commit 93fb25c

Please sign in to comment.