Memberships is a feature that makes it possible to require visitors to have an account in order to access content.
request_contact.is_logged_in
indicates if the current visitor is signed in to the website through memberships. It can be used within an if
statement to conditionally render certain content, allowing you to individually cater your visitor’s experience.
request_contact.list_memberships
HubL variable, which returns a dict of list IDs the logged in contact is a member of.
hs-member-content-access=<true/false>
When true
, the content is private and cannot be viewed by a viewer who is not logged in.
For example, you could update your blog listing template with the following. Note that the lock-icon
class can be any value, as long as you use the same value in your CSS to style the locked post indicator.
hs-member-content-access
attribute. Note that the lock-icon
class is just an example; you can use any value, as long as it matches the HTML class shown in the first code example above.
flag_content_for_access_check()
function is calling an API to check whether the current visitor has access to the content based on the visitor cookies that are passed along with the request. If you’d like to create your own JavaScript solution, you can call this API directly.
To check whether or not a post is locked to the current visitor, you can make a POST
request to https://your-domain.com/_hcms/content-access/get-gated-content-ids-for-member
. The request body should include an object with a contentIds
array containing the IDs of the blog posts that you want to check member access for.
For example, if you wanted to check whether blog posts with the IDs of 10
, 11
, and 12
are locked to the visitor, your request body would be:
<your domain>/_hcms/mem/login
<your domain>/_hcms/mem/logout
membership_social_logins
module.
Add social login to your membership pages