Unable to fetch hidden tiers using get with filter

Issue Summary

I’m trying to show “hidden” tiers on a custom template page.

I have the following in portal config:

I’m trying to fetch the unchecked tiers using the following:

{{#get "tiers" include="monthly_price,yearly_price,benefits" filter="visibility:none" limit="all"}}

But the query returns empty. If I change it to visibility:public, the two checked tiers show up.

All tiers show up when I hit the API endpoint directly, http://127.0.0.1:2368/ghost/api/content/tiers/

{
  "tiers": [
    {
      "id": "64d410421546084bb3c3f75e",
      "name": "Free",
      "description": null,
      "slug": "free",
      "active": true,
      "type": "free",
      "welcome_page_url": null,
      "created_at": "2023-08-09T22:16:34.000Z",
      "updated_at": "2023-08-09T22:16:34.000Z",
      "visibility": "public",
      "benefits": [
      ],
      "trial_days": 0
    },
    {
      "id": "64d410421546084bb3c3f75f",
      "name": "Supporter",
      "description": null,
      "slug": "default-product",
      "active": true,
      "type": "paid",
      "welcome_page_url": null,
      "created_at": "2023-08-09T22:16:34.000Z",
      "updated_at": "2023-10-17T23:22:34.000Z",
      "visibility": "public",
      "benefits": [
      ],
      "currency": "USD",
      "monthly_price": 400,
      "yearly_price": 4000,
      "trial_days": 0
    },
    {
      "id": "652f1750f2633823c3a0f875",
      "name": "Basic Sponsor",
      "description": null,
      "slug": "basic-sponsor",
      "active": true,
      "type": "paid",
      "welcome_page_url": null,
      "created_at": "2023-10-17T23:22:56.000Z",
      "updated_at": "2023-10-18T00:15:38.000Z",
      "visibility": "none",
      "benefits": [
      ],
      "currency": "USD",
      "monthly_price": 4000,
      "yearly_price": 35000,
      "trial_days": 0
    },
    {
      "id": "652f1765f2633823c3a0f879",
      "name": "Special Sponsor",
      "description": null,
      "slug": "special-sponsor",
      "active": true,
      "type": "paid",
      "welcome_page_url": null,
      "created_at": "2023-10-17T23:23:17.000Z",
      "updated_at": "2023-10-18T00:15:38.000Z",
      "visibility": "none",
      "benefits": [
      ],
      "currency": "USD",
      "monthly_price": 9900,
      "yearly_price": 80000,
      "trial_days": 0
    },
    {
      "id": "652f1779f2633823c3a0f87d",
      "name": "Global Sponsor",
      "description": null,
      "slug": "global-sponsor",
      "active": true,
      "type": "paid",
      "welcome_page_url": null,
      "created_at": "2023-10-17T23:23:37.000Z",
      "updated_at": "2023-10-18T00:15:38.000Z",
      "visibility": "none",
      "benefits": [
      ],
      "currency": "USD",
      "monthly_price": 49900,
      "yearly_price": 450000,
      "trial_days": 0
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "pages": 1,
      "limit": 5,
      "total": 5,
      "prev": null,
      "next": null
    }
  }
}

Setup information

Ghost Version

v5.69.3

Node.js Version

v16.15.0

How did you install Ghost?

Self hosted, dev install

Provide details of your host & operating system

OSX

Looks like either a bug or a documentation error! That is indeed what the docs say to do!

Like @Cathy_Sarisky said, I don’t see anything going wrong in your code.

Can you add this code to your theme’s default.hbs file to help debug?

{{#get "tiers"}}
  {{log this}}
{{/get}}

Then, stop Ghost (ghost stop) and restart it in dev mode: ghost run -D. Finally, refresh your site and check the output in the console. All of your tiers will be listed with the corresponding visibility issues. Please share what it says!

1 Like

hi @RyanF

Did as you suggested and see the following in my console on my local installation

{
  tiers: [
    {
      id: '64d410421546084bb3c3f75e',
      name: 'Free',
      description: null,
      slug: 'free',
      active: true,
      type: 'free',
      welcome_page_url: null,
      created_at: 2023-08-09T22:16:34.000Z,
      updated_at: 2023-08-09T22:16:34.000Z,
      visibility: 'public',
      benefits: [],
      trial_days: 0
    },
    {
      id: '64d410421546084bb3c3f75f',
      name: 'Supporter',
      description: null,
      slug: 'default-product',
      active: true,
      type: 'paid',
      welcome_page_url: null,
      created_at: 2023-08-09T22:16:34.000Z,
      updated_at: 2023-10-17T23:22:34.000Z,
      visibility: 'public',
      benefits: [],
      currency: 'USD',
      monthly_price: 400,
      yearly_price: 4000,
      trial_days: 0
    },
    {
      id: '652f1750f2633823c3a0f875',
      name: 'Basic Sponsor',
      description: null,
      slug: 'basic-sponsor',
      active: true,
      type: 'paid',
      welcome_page_url: null,
      created_at: 2023-10-17T23:22:56.000Z,
      updated_at: 2023-10-18T00:15:38.000Z,
      visibility: 'none',
      benefits: [],
      currency: 'USD',
      monthly_price: 4000,
      yearly_price: 35000,
      trial_days: 0
    },
    {
      id: '652f1765f2633823c3a0f879',
      name: 'Special Sponsor',
      description: null,
      slug: 'special-sponsor',
      active: true,
      type: 'paid',
      welcome_page_url: null,
      created_at: 2023-10-17T23:23:17.000Z,
      updated_at: 2023-10-18T00:15:38.000Z,
      visibility: 'none',
      benefits: [],
      currency: 'USD',
      monthly_price: 9900,
      yearly_price: 80000,
      trial_days: 0
    },
    {
      id: '652f1779f2633823c3a0f87d',
      name: 'Global Sponsor',
      description: null,
      slug: 'global-sponsor',
      active: true,
      type: 'paid',
      welcome_page_url: null,
      created_at: 2023-10-17T23:23:37.000Z,
      updated_at: 2023-10-18T00:15:38.000Z,
      visibility: 'none',
      benefits: [],
      currency: 'USD',
      monthly_price: 49900,
      yearly_price: 450000,
      trial_days: 0
    }
  ],
  meta: {
    pagination: { page: 1, pages: 1, limit: 5, total: 5, prev: null, next: null }
  },
  pagination: { page: 1, pages: 1, limit: 5, total: 5, prev: null, next: null }
}
[2023-10-18 22:39:46] INFO "GET /membership/" 200 153ms
[2023-10-18 22:39:47] INFO "GET /assets/css/screen.css?v=362b14e292" 304 40ms
[2023-10-18 22:39:47] INFO "GET /assets/css/swaylocks.css?v=362b14e292" 304 40ms
[2023-10-18 22:39:47] INFO "GET /assets/js/jquery-3.2.1.min.js?v=362b14e292" 304 40ms
[2023-10-18 22:39:47] INFO "GET /assets/js/global.js?v=362b14e292" 304 40ms
[2023-10-18 22:39:47] INFO "GET /assets/js/post.js?v=362b14e292" 304 9ms
[2023-10-18 22:39:47] INFO "GET /members/api/member/" 200 9ms
[2023-10-18 22:39:47] INFO "GET /rss/" 304 53ms
[2023-10-18 22:39:47] INFO "GET /ghost/api/content/tiers/?key=d4a35d92fa516bc4d4e255759b&limit=all&include=monthly_price,yearly_price,benefits" 304 47ms
[2023-10-18 22:39:47] INFO "GET /ghost/api/content/newsletters/?key=d4a35d92fa516bc4d4e255759b&limit=all" 304 52ms
[2023-10-18 22:39:47] INFO "GET /ghost/api/content/settings/?key=d4a35d92fa516bc4d4e255759b&limit=all" 304 66ms
[2023-10-18 22:40:18] INFO Worker for job "mentions-email-report" online
[2023-10-18 22:40:18] INFO Worker for job mentions-email-report sent a message: done

Sure looks like they’re available!
Can you share the code inside the get that isn’t giving results? Does it also not give results on the dev setup?

Same version of ghost?

@Cathy_Sarisky glad to.

I’m using the Basho theme which does a bunch of nesting. Hard to believe that’s the issue, but I’ll continue to experiment on my side, until it’s confirmed this is a bug…

Here’s how the theme stack is set up. The code works, except for the get/filter in question…

Things start with a custom page template called custom-sponsorships.hbs (Note: I’m simplifying here where it makes sense.)

custom-sponsorships.hbs

{{!< default}}
{{#post}}
	<div class="post-section">
		{{>post_header sponsorship_page=true}}
	</div>
{{/post}}

post_header.hbs

<div class="post-header{{>partial_mode}}">
  <!-- bunch of header stuff goes here removed for easier reading -->

  {{#if sponsorship_page}}
    {{>members/sponsor_tiers}}
  {{/if}}
</div>

members/sponsor_tiers.hbs

<div class="membership-section global-padding">
  <div class="global-subtitle">
    <small class="global-subtitle-title">{{{t "See {start-bold}pricing plans{end-bold}" start-bold="<span>" end-bold="</span>"}}}</small>
  </div>
  <div class="membership-wrap global-radius{{#if feature_image}} global-bg-image" style="background-image: url({{feature_image}}){{/if}}">
    <div class="membership-switch" data-active-price="yearly">
      <button data-price="monthly">{{t "Monthly"}}</button>
      <button data-price="yearly">{{t "Yearly"}}</button>
    </div>
    <div class="membership-cards">
      {{^if @member}}
        {{#if sponsorship_page}}
          {{#get "tiers" include="benefits" filter="visibility:none"}}
            {{#foreach tiers}}
              <div class="membership-card">
                <div class="membership-card-content">
                  <div class="membership-card-label">{{name}}</div>
                  <h2 class="membership-card-price">{{t "$"}}0</h2>
                  {{#if description}}<p>{{description}}</p>{{/if}}
                  {{#if benefits}}
                  <div class="membership-card-list">
                    <ul>
                      {{#foreach benefits as |benefit|}}
                      <li>{{benefit}}</li>
                      {{/foreach}}
                    </ul>
                  </div>
                  {{/if}}
                </div>
                <a href="{{@site.url}}/signup/" class="membership-button global-button">{{t "Sign up for free"}}</a>
              </div>
            {{/foreach}}
          {{/get}}
        {{/if}}
      {{/if}}
      {{#get "tiers" include="monthly_price,yearly_price,benefits" filter="visibility:none" limit="all"}}
        {{#foreach tiers}}
          <div class="membership-card">
            <div class="membership-card-content">
              <div class="membership-card-label">{{name}}</div>
              <h2 class="membership-card-price" data-monthly>{{#if monthly_price}}{{price currency=currency}}{{price monthly_price}}{{else}}$0{{/if}}<span>/{{t "month"}}</span></h2>
              <h2 class="membership-card-price" data-yearly>{{#if yearly_price}}{{price currency=currency}}{{price yearly_price}}{{else}}$0{{/if}}<span>/{{t "year"}}</span></h2>
              {{#if description}}<p>{{description}}</p>{{/if}}
              {{#if benefits}}
              <div class="membership-card-list">
                <ul>
                  {{#foreach benefits as |benefit|}}
                  <li>{{benefit}}</li>
                  {{/foreach}}
                </ul>
              </div>
              {{/if}}
            </div>
            <a href="javascript:" data-portal="signup/{{id}}/monthly" class="membership-button global-button" data-monthly>{{t "Sign up now"}}</a>
            <a href="javascript:" data-portal="signup/{{id}}/yearly" class="membership-button global-button" data-yearly>{{t "Sign up now"}}</a>
          </div>
        {{/foreach}}
      {{/get}}
    </div>
  </div>
  {{^if @member}}
    {{#if sponsorship_page}}
      <small class="global-question">{{t "Already have an account?"}} <a href="{{@site.url}}/signin/">{{t "Sign in"}}</a></small>
    {{/if}}
  {{/if}}
</div>

If that’s over complicating things…if I rewrite the custom-sponsorships.hbs like so:

{{!< default}}
{{#post}}
<div class="post-section">
  {{#get "tiers" include="monthly_price,yearly_price,benefits" filter="visibility:none" limit="all"}}
        {{#foreach tiers}}
          <div class="membership-card">
            <div class="membership-card-content">
              <div class="membership-card-label">{{name}}</div>
              <h2 class="membership-card-price" data-monthly>{{#if monthly_price}}{{price currency=currency}}{{price monthly_price}}{{else}}$0{{/if}}<span>/{{t "month"}}</span></h2>
              <h2 class="membership-card-price" data-yearly>{{#if yearly_price}}{{price currency=currency}}{{price yearly_price}}{{else}}$0{{/if}}<span>/{{t "year"}}</span></h2>
              {{#if description}}<p>{{description}}</p>{{/if}}
              {{#if benefits}}
              <div class="membership-card-list">
                <ul>
                  {{#foreach benefits as |benefit|}}
                  <li>{{benefit}}</li>
                  {{/foreach}}
                </ul>
              </div>
              {{/if}}
            </div>
            <a href="javascript:" data-portal="signup/{{id}}/monthly" class="membership-button global-button" data-monthly>{{t "Sign up now"}}</a>
            <a href="javascript:" data-portal="signup/{{id}}/yearly" class="membership-button global-button" data-yearly>{{t "Sign up now"}}</a>
          </div>
        {{/foreach}}
      {{/get}}
</div>
{{/post}}

I get no cards, but if I change visibility:none to visibility:public the public tiers show.

@mpaler {{#foreach}} will filter on visibility to avoid accidentally showing things which aren’t meant to be public.

It looks like it hasn’t been documented (cc @RyanF) but you should be able to override the default visibility filter with {{#foreach visibility="all"}} or {{#foreach visibility="none"}}

3 Likes

Updated the foreach docs to include the visibility attribute!

3 Likes


Thank you…

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.