Trouble accessing labels from post.hbs

Hi folks, I would like to access a member’s labels from the post.hbs file.

Here is the code I am using to show the labels on the post if the member is logged in and not paid:

    <section class="gh-content gh-canvas">
        {{#if @member}}
            {{#if @member.paid}}
                {{content}}
            {{else}}
                <div class="gh-login-prompt">
                    <p>Post URL: {{url}}</p>
                        {{#if @member.labels}}
                            {{#each @member.labels}}
                                <p>{{this}}</p>
                            {{/each}}
                        {{else}}
                            <p>No labels associated with this member.</p>
                        {{/if}}
                </div>
            {{/if}}
        {{else}}
            <div class="gh-login-prompt">
                <p>Please <a href="{{@site.url}}/#/portal/signin">log in</a> or <a href="{{@site.url}}/#/portal/signup">sign up</a> to view this content.</p>
                <p><a href="{{url}}">View Post</a></p>
            </div>
        {{/if}}
    </section>

Currently, this is just showing “No labels associated with this member.” even though there are multiple labels associated with this member.

Labels aren’t available within the templating layer. To see which data is available, check this out: Ghost Theme Development: Building custom membership flows

Thanks @RyanF , I appreciate that clarity and was thinking that may have been the case.

I’m trying to build some micropayments functionality so that a member can pay to get access to just one post. Ideally I would have a way to attach metadata to a user, in a way that the metadata can be available from the templating layer. It seems this isn’t possible?

Alternatively I could tag each post with the names of users who have access. However, that will result in a lot of tags per post.

Have you any other suggestions?

I suppose the last alternative is to conditionally show content after posting to an external that returns the status of the member with respect to that post.

This won’t be trivial to implement because you have payments, users, auth, content, and integration. You’d need to set up some kind of proxy service (server, db) that uses the Admin API in conjunction with other APIs/SDKs.

1 Like

Yeah agreed, I’ve been able to build a plugin pretty easily for WordPress but it’s just challenging here because I either have to really get into Ghost core, or, as you said, replicate a lot in a proxy service.

I appreciate the answers, nonetheless. I’ll mark this resolved.

1 Like