Is there a way of showing content in a Statamic antlers template if a user is authenticated?

27 views Asked by At

I'm having some issues trying to get some content to display in an admin panel when a user is logged into it. I am using Antlers templates in Statamic with Laravel in there too and can't find a template tag that could be used for checking if the user is authenticated?

I've tried looking at the Statamic documentation but couldn't find anything that I think would have helped me with this.

1

There are 1 answers

2
Intekhab Khan On

To check if a user is logged in and display content based on this condition within an Antlers template, you can use the {{ user }} tag or its aliases. Here’s a simple way to do it:

    {{ if user }}
    <!-- Content to display if the user is logged in -->
    <p>Welcome back, {{ user:name }}!</p>
{{ else }}
    <!-- Content to display if the user is not logged in -->
    <p>Please <a href="/login">log in</a> to access the admin panel.</p>
{{ /if }}