Pulling content from one page into another - with tiers

Hi all,

I hit an interesting issue I’m hoping you can help me with. Forgive me for not having a 100% reproducible example here - It’s possible that I’m just doing something wrong with how I’m using {{content}} and context…

I was trying to create a .hbs file for a page that would pull content from a couple of other pages/posts. I’ve done this lots of times before, for example, to build a custom index page for posts. In this case, however, I needed the CONTENT of the page, not just title and excerpt. I can do this just fine, IF the pages/posts are available for all members. However, in this case, I have pages that are restricted to paid members with a specific tier. The page template I am aggregating the contents to is also restricted to that tier.

So I have a {{#get pages}} to get the pages whose data I want to include, and then a {{#foreach}} to loop over them. (Along with some #match logic to make sure that only pages the user is allowed to access have contents included.) That got me access to the {{title}} and {{excerpt}}, authors, tags, etc. But when I added {{content}}, all I got from the content helper was the public preview and call to action. To be clear, I was definitely signed in as a user who has access to the contents. And visiting the contents pages directly works fine. But {{#get}}-ing pages with these contents and looping over them produces only the CTA and any public preview.

I don’t see documentation on the {{content}} helper really. Am I missing something obvious? How can I get the content helper to understand that the user has access? Or to ignore checking for access?

Documentation, hints, or working examples would be much appreciated. For my client, it’s going to be the difference between being able to edit her content or not (as my workaround has a bunch of extra stuff hard-coded that shouldn’t be), so thank you in advance for any help!

Hey @Cathy_Sarisky!

This should be working, as per this commit which added support for members to the get helper.

I wonder if it’s a quirk of posts vs pages.

Fancy having a look or if not raising it as a bug on the repo?

Thanks for confirming it should work! I’ll see if I can nail down the edge (?) case that isn’t!

Are you able to share the template code? At least the relevant bits.

I’m imagining it’s something like this:

{{#get "pages" filter="..."}}
  {{#foreach pages}}
    <div>{{content}}</div>
  {{/foreach}}
{{/get}}

That’s roughly what it looked like, yeah, Ryan. I’ll create a MWE (or maybe minimal BROKEN example) and post it when I get a chance.

1 Like

I just tested this, and it seemed to work as expected.

The full content was output when I had access (signed in as a paid user) but showed the CTA when not.

:thinking:

As promised, a minimal broken example:

{{!< default}} <main class="gh-main gh-outer">
    <div class="gh-inner">
        {{#get "pages" filter="tags:[grabme]"}}
        {{#foreach pages}}
        <hr>
        <div>
            POST NAME: {{title}} <a href="{{url}}">LINK TO POST</a>

            {{#if access }} {{content}} 
            {{else}}You can't read this!, but try anyway: <p>{{content}}</p>
            {{/if}}

            <p>Check post's specific status:
            {{#has visibility="public"}}
                This content is free</p>
            {{/has}}

            {{#has visibility="paid"}}
            This content is paid</p>
            {{/has}}

            {{#has visibility="filter"}}
            Filtered content for {{tier}}.</p>
            {{/has}}

        </div>

        {{/foreach}}
        {{/get}}
    </div>
    </main>

I have four pages, one paid, one public, one for one tier, one for a different. My test user is in one tier, not the other.

Here’s the output:

Public and paid pages work as expected. But when I restrict the page to a specific tier, I don’t get the content returned for that user, although clicking the link to go directly to the page in question works fine and gives me the full content.

Update: Not a page-specific gremlin. The problem also occurs with posts instead of pages.

And I pushed this theme code to Ghost Pro, so it’s not that my dev box is out of date. :)

One other observation: For tier-restricted posts/pages, I’m getting NEITHER the content, NOR the CTA text. (When my user is logged out, I get the CTA were expected on paid content.)

Ok so as I’m understanding, this is a tiers specific bug. Would you be up for raising it on the main repo?

Yup. Was just waiting on confirmation that I wasn’t just doing something wrong with tiers. :) I’ll go file it.