[Question] Handlebar for 'locked' posts

I wonder if we can mix {{if}} with a selector for paid or locked blogposts.

I want to use this handlebars to avoid addons on locked articles like comments or TOC.

I searched here, on Github and docs but I didn’t found this specific question already answered.

Thanks for your time! :slight_smile:

You can’t use selectors, but you can wrap your elements with a check.
For example, if you don’t want to show elements (comments or toc) for users that don’t have access to the post:

{{#if access}}
  /* your toc or comment code */
{{/if}}
1 Like

It seems to block public articles as well?

Make sure to use the condition in the post context:

{{#post}} 
   .... 
{{/post}}

I used the selector between #post context and I see that’s hidding the content on public posts too.

It seems to be working only with locked (with access) posts and not with every post (like those with free access)?

I don’t have your code/setup, so I can’t say for sure, but the above approach works fine in my case.

I have comments wrapped like that:

{{#post}}
  ..other post stuff

  {{#if access}}
    <div class="content-width">
      {{comments 
        title=(t 'Comments')
        count=true
        mode=auto
      }}
    </div>
  {{/if}}
{{/post}}

With this, the comment section is rendered on public posts, and on member-only/paid posts it’s only rendered when the user has access.

1 Like