My archive page is meant to be only accessible to paid subscribers. I read the docs on how to enable this functionality, but it does not appear to be working correctly. Can someone help me figure out what I am doing wrong?
{{#if access}}
<Code block to create archive page>
{{else}}
<p>no worky</p>
{{/if}}
{{content}}
My template has the appropriate content-cta.hbs file in the partials folder. I am building off of the Ghost Solo theme which already included that. The only way I can get this to partially work is to change access above to @member. However, I would like to get this to work as documented so I can just set the access control in the page setting menu as needed.
I have even tried the example right out of the documentation and I get a blank page, even when access for the page is set to public. Now, I feel like this might have something to do with the fact that this is a setting for a page, not a post. It is also a custom page with a custom template behind it.
{{#post}}
<h1>{{title}}</h1>
{{#if access}}
<p>Thanks for being a member...</p>
{{else}}
<p>You need to become a member in order to read this post... </p>
{{/if}}
{{content}}
{{/post}}
But the above does not work for this page and comes straight from the developer docs.
If you’re running locally, what do your logs say?
I am not getting anything in the error log. I am getting so much in the regular production log that I do not understand. I am behind cloudflare, but I don’t think this is a caching problem because the page changes as I am testing out different code options.
If you’re running in development/locally, ghost run -D produces lots of helpful messages. Having a blank page usually means an error in the hbs structure (or your template isn’t supposed to render anything anyway… )
I will give that a try. Seems like the simple code below directly from the docs should work without so much trouble, though. I blew away everything I had built just to see if I could replicate the example from the docs. Solo theme does use a custom cta, so maybe that is throwing things off. I didn’t expect this step to be so difficult.
It works if I use the {{#if @member}}, but the docs say this should work also.
Point of clarification after trying to run in development mode with errors. I am not running “locally” or in development mode. I am self-hosting a production server. My backend is MySQL. Trying to run with the -D argument only starts local development instance with a different, unconfigured database.
oh hang on a second. Was your example above in partials/content-cta, or in the post.hbs?
Here’s code that works in partials/content-cta.hbs:
There are also some examples here:
Actually, I was using the snippet above in a page template file. But I do have a content-cta in partials that looks like the snippet you posted. I think it might have something to do with routing. I am routing /archive/ to my archive.hbs template. Maybe I do not have the routing set up correctly to work with my template and the cta.
routes:
/archive/: archive
collections:
/:
permalink: /{slug}/
template: index
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/
Then I have a simple archive.hbs file with the snippet I posted earlier just trying to test a simple page with access filtering.
I confirmed that regular pages are working with access filtering, if created through the dashboard and not linked with routes.yaml to a template. However, the template is where I am creating all of my code that I want to do the filtering on, so I need to figure out how to make that work.
Should I be using the data property on my route? If so, what would I use there?
OMG. I figured it out. In my routes.yaml, I needed to use the data property. I guess that allowed the page to look at my access filtering setting in the dashboard for the page. That took me so long to figure out. Thank you @Cathy_Sarisky for helping me think!
1 Like
Adding controller: channel to my routes.yaml breaks this configuration, but from everything I am reading, I need to do that for pagination.