From d249c9241572dd0bab2345ccdcd454f145015a4e Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 14 Mar 2017 16:00:12 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=F0=9F=8E=A8=20Allow=20foreach=20el?= =?UTF-8?q?se=20inside=20of=20get=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #7242 - before this, the get helper's else was used for empty resultsets - the argument was made that we should fall through to a foreach or with helper's else instead - I agree that this is the more natural, consistent approach, and so would like to change it for Ghost 1.0 E.g. as of this PR we now have: {{#get "posts" filter="tag:doesnt-exist"}} {{#foreach posts}} {{else}} this ges executed because there are no results {{/foreach}} {{/get}} instead of {{#get "posts" filter="tag:doesnt-exist"}} {{#foreach posts}} {{else}} {{/foreach}} {{each}} this ges executed because there are no results {{/get}} --- core/server/helpers/get.js | 5 ----- core/test/unit/server_helpers/get_spec.js | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/core/server/helpers/get.js b/core/server/helpers/get.js index aa483f596436..aa9c30e43110 100644 --- a/core/server/helpers/get.js +++ b/core/server/helpers/get.js @@ -120,11 +120,6 @@ get = function get(resource, options) { return apiMethod(apiOptions).then(function success(result) { var blockParams; - // If no result is found, call the inverse or `{{else}}` function - if (_.isEmpty(result[resource])) { - return options.inverse(self, {data: data}); - } - // block params allows the theme developer to name the data using something like // `{{#get "posts" as |result pageInfo|}}` blockParams = [result[resource]]; diff --git a/core/test/unit/server_helpers/get_spec.js b/core/test/unit/server_helpers/get_spec.js index 3e352d727299..b0f151423e8a 100644 --- a/core/test/unit/server_helpers/get_spec.js +++ b/core/test/unit/server_helpers/get_spec.js @@ -218,10 +218,10 @@ describe('{{#get}} helper', function () { 'posts', {hash: {filter: 'tags:none'}, fn: fn, inverse: inverse} ).then(function () { - fn.called.should.be.false(); - inverse.calledOnce.should.be.true(); - inverse.firstCall.args[1].should.be.an.Object().and.have.property('data'); - inverse.firstCall.args[1].data.should.be.an.Object().and.not.have.property('error'); + fn.calledOnce.should.be.true(); + fn.firstCall.args[0].should.be.an.Object().with.property('posts'); + fn.firstCall.args[0].posts.should.have.lengthOf(0); + inverse.called.should.be.false(); done(); }).catch(done);