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
{{content}}
{{/foreach}}
{{/get}}
(...)
{{else}}
(...)
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
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 @brightthemes! 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}}.
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?