The #has handlebars helper not working with visibility?

I was just doing some development on my theme and I wanted to have custom messages on paid and members only posts. So I figured I would look up the documentation – and it turns out Ghost supports a #has function.

I tried to test the following code, but it did not work. The syntax is correct, else handlebars handily fails to load the page, but it does not have the desired effect.

{{#has visibility="paid"}}
    <span class="post-visibility post-visibility-{{visibility}}">Premium Post</span>
{{else has visibility="members"}}
    <span class="post-visibility post-visibility-{{visibility}}">Subscribers Only</span>
{{/has}}

It seems that the equality never goes through, even though the only options are paid, members and public.

So I’m confused, how am I supposed to implement this sort of functionality?

So the has helper doesn’t work with members data, but there are a couple of variables available:

https://ghost.org/docs/members/content-visibility

I don’t think it’s possible for you to run your logic using just helpers - there is boolean member information but not boolean post visibility information :thinking:

Yeah unfortunately, this is not possible. But maybe in the future, when the helpers are extended to the new members helpers.

Hello! @MLFromScratch

Maybe it will be useful to you:

<style>
.premium,
.free {
   display: none;
}

.premium.paid,
.free.members {
   display: block;
}
</style>

{{#if access}}
{{content}}
{{else}}			
<div class="premium {{visibility}}">
	<h2>Paying subscribers only</h2>
	{{#if @member}}
	<p>Upgrade your account</p>
	{{else}}
	<p>Sign up now and upgrade your account</p>
	{{/if}}
</div>
<div class="free {{visibility}}">
	<h2>Subscribers only</h2>
	<p>Sign up now</p>
</div>
{{/if}}
2 Likes

Hey fueko, this definitely does look like a solution, I was just hoping for something much simpler :slight_smile:

1 Like