5

I want to have a public and private (logged in users) section on the front-end. Is that possible on craft?

1 Answer 1

8

Yes. You need to build a frontend login form and then block non logged in users from seeing the entries with something along the lines of this:

{% if craft.session.isLoggedIn %}
    {# put content here #}
{% endif %}

You can also check if the user belongs to a specific group with isInGroup('groupHandle') (more here)

5
  • 4
    You can also use {% if currentUser %} , which will return false if the user is not logged in.
    – Lindsey D
    Aug 10, 2015 at 17:56
  • any difference between this and {% requireLogin %}?
    – cmcjane
    Aug 22, 2015 at 22:03
  • 1
    {% requireLogin %} will redirect you to your loginPath if you are not logged in. More here
    – megatrond
    Aug 23, 2015 at 7:10
  • Something seems to have changed. None of these seem to work anymore in Craft CMS 3.3.16.3 {% if craft.session.isLoggedIn %} or {% if currentUser %} - Mr. Sadface.
    – Josh Coast
    Apr 13, 2020 at 17:42
  • {% if currentUser %} should definitely still work: docs.craftcms.com/v3/dev/global-variables.html#currentuser There's also the page-wide {% requireLogin %} tag, but that probably doesn't prevent the entry from showing up on listing pages.
    – Sandwich
    Apr 13, 2020 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.