diff --git a/ghost/core/core/frontend/helpers/foreach.js b/ghost/core/core/frontend/helpers/foreach.js index 51a1c78632..1dbabf9c25 100644 --- a/ghost/core/core/frontend/helpers/foreach.js +++ b/ghost/core/core/frontend/helpers/foreach.js @@ -31,6 +31,14 @@ module.exports = function foreach(items, options) { if (Object.values(items).length > 0 && checks.isPost(Object.values(items)[0])) { visibility = visibility || 'all'; } + } + + if (_.isArray(items) && items.length > 0 && checks.isNewsletter(items[0])) { + visibility = visibility || 'all'; + } else if (_.isObject(items) && _.isArray(Object.values(items))) { + if (Object.values(items).length > 0 && checks.isNewsletter(Object.values(items)[0])) { + visibility = visibility || 'all'; + } } // Exclude items which should not be visible in the theme items = ghostHelperUtils.visibility.filter(items, visibility); diff --git a/ghost/core/core/frontend/helpers/get.js b/ghost/core/core/frontend/helpers/get.js index 5be21279e9..e682f3bd3a 100644 --- a/ghost/core/core/frontend/helpers/get.js +++ b/ghost/core/core/frontend/helpers/get.js @@ -33,6 +33,9 @@ const RESOURCES = { }, tiers: { alias: 'tiersPublic' + }, + newsletters: { + alias: 'newslettersPublic' } }; diff --git a/ghost/core/core/frontend/services/data/checks.js b/ghost/core/core/frontend/services/data/checks.js index 4308ea1315..76b43fa5b5 100644 --- a/ghost/core/core/frontend/services/data/checks.js +++ b/ghost/core/core/frontend/services/data/checks.js @@ -3,6 +3,11 @@ function isPost(jsonData) { Object.prototype.hasOwnProperty.call(jsonData, 'title') && Object.prototype.hasOwnProperty.call(jsonData, 'slug'); } +function isNewsletter(jsonData) { + return Object.prototype.hasOwnProperty.call(jsonData, 'name') && + Object.prototype.hasOwnProperty.call(jsonData, 'subscribe_on_signup') && Object.prototype.hasOwnProperty.call(jsonData, 'visibility'); +} + function isPage(jsonData = {}) { return Object.prototype.hasOwnProperty.call(jsonData, 'show_title_and_feature_image'); } @@ -24,6 +29,7 @@ function isNav(jsonData) { module.exports = { isPost, + isNewsletter, isPage, isTag, isUser, diff --git a/ghost/core/test/unit/frontend/helpers/foreach.test.js b/ghost/core/test/unit/frontend/helpers/foreach.test.js index 9f7a199de8..2e23503948 100644 --- a/ghost/core/test/unit/frontend/helpers/foreach.test.js +++ b/ghost/core/test/unit/frontend/helpers/foreach.test.js @@ -402,6 +402,27 @@ describe('{{#foreach}} helper', function () { shouldCompileToExpected(templateString, objectHashWithVis, expected); }); + it('foreach with newsletters with members visibility', function () { + const newsletterObjectHashWithVisibility = { + newsletters: { + first: {name: 'first', visibility: 'members', subscribe_on_signup: true}, + second: {name: 'second', visibility: 'members', subscribe_on_signup: true}, + third: {name: 'third', visibility: 'paid', subscribe_on_signup: false} + } + }; + const newsletterArrayHashWithVisibility = { + newsletters: [ + {name: 'first', visibility: 'members', subscribe_on_signup: true}, + {name: 'second', visibility: 'members', subscribe_on_signup: true}, + {name: 'third', visibility: 'paid', subscribe_on_signup: false} + ] + }; + const templateString = '