Displaying the latest post (member protection) inside the user account (member area), viewing rights issue

I’m struggling with the following: I’m using Lyra, Ghost 3.x as the base and I’m trying to

  • display the latest post
  • containing the tag ‘performance’
  • within the user account (so they have that right then and there after logging in)
  • the posts are restricted to members

In short, no matter what I do, I’m failing. The closest I’ve gotten in accomplishing it is to have the post set to public. But more for my setup here:

    {{else if @member}}
      {{#get "posts" limit="1" filter="tag:performance"}}
        {{#foreach posts visibility="members"}} //or all, doesn't change the outcome

Now, with having the post set to public, it shows perfectly inside this page, but since the posts need to be hidden to the public it’s set to member, and when that’s the case, then within the account it shows the

This post is for subscribers only
Upgrade your account


Can anyone help? Thanks a lot!

tried to make the original post more clear, but looks like there is no edit button?

In any case, the relevant code is inside account.hbs. and a page.hbs, they both react the same.

Does anyone have a pointer to what I’m missing here? I’m pretty sure it’s obvious, but I just cannot find it.

P.s. updated to Ghost 4.x, but same story. Thank yall

Within your {{get}} you set the limit to 1 and that means you fetch the latest post with that tag, which could have different visibility then what you expect.

{{content}} might not behave as expected in this context, I would suggest using another attribute from the post instead, maybe {{title}} at least for testing if it works.

Thanks for the reply @bironthemes! What do you mean different than I expect? I know that all posts inside the performance tag will be set to “member”. I want to output that onto the page.
I don’t need the title, just the content of the post, but for testing purposes I’ve named the outputs, and the output that works is:

Posts with performance tag, but put to “public” visibility.
When the post is set to “member” it displays the “This post is for subscribers only” CTA.

I’m not sure why that’s happening since we are actually within the if @member tag?

From my experience, fetching posts with the {{get}} helper doesn’t determine the access property (checking if you have access to the post), so in that case your content will not render… You could try with the routes.yaml to assign those posts to the /account/ route and then you would not need the {{get}}.

1 Like

thanks, that’s an idea @bironthemes.

Would that be a simple foreach loop then? Then I could also filter for the tag, though and wouldn’t need the routes (at least that works in the test)? However, I can’t filter for the latest post only? Or how did you see routes setup?

{{#foreach posts}}
  {{#has tag="performance"}}

Thank you <3

FTR this actually solves it, thank you.

{{#foreach posts limit="1"}}
<a href="{{url}}">{{name}}</a>
1 Like