I want to have a public and private (logged in users) section on the front-end. Is that possible on craft?
1 Answer
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)
-
4You can also use
{% if currentUser %}
, which will returnfalse
if the user is not logged in. Commented Aug 10, 2015 at 17:56 -
-
1
-
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. Commented 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.– SandwichCommented Apr 13, 2020 at 18:06