Forum

Thread tagged as: Addons, Blog, Members

Can I password protect individual blog posts with members app?

Hello,

I am creating a blog with perch, which is going awesome so far, but I would like to have the ability to make some posts accessible to members only. Can this be achieved using the members app? If so, how would I go about this?

Mark Fenton

Mark Fenton 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, I think that's probably possible!

You'd need to add a field to your post.html template:

<perch:blog id="members_only" type="checkbox" value="1" label="Members only post" />

and then create a template for using to display posts, something like post_with_members_check.html or whatever.

<perch:if exists="members_only">
    <perch:member logged-in="true"> 
        <perch:template path="blog/post.html" />
    <perch:else:member />
        <p>You must be logged in to read this post.</p>
    </perch:member>
</perch:if>

<perch:if not-exists="members_only">
    <perch:template path="blog/post.html" />
</perch:if>

I think that should work, off the top of my head. Let me know if you hit problems and we'll go from there.

Thank you so much for that Drew, I'll give it a go and let you know if I get stuck.