How to restrict access to some section in front-end for admin user only? I know this is a basic question, but i never use Craft this way.

I need to show a section ( list of items ) in the frontend but only available for admin users ( that are already logged in the control panel ). 

How can achieve this restriction from the template?

Thanks!
One option is to do this:

{% if currentUser.admin ?? false %}

    ...this code can only be seen by admins...

{% endif %}


currentUser is a Global Variable on which you can pass the admin property. ?? is a null-coalescing operator which returns false if the currentUser (if there is one) is not an admin.

Edit:

So if you want to show this section to anyone logged in to the admin or client account in Craft Client, I'd recommend doing the following:

{% if currentUser ?? false %}

    ...this code can only be seen by admins...

{% endif %}


Basically, this says if the current user is logged in, display the contents. Since the only ones with logins are you and the client, this will only display the content to you!



If you'd like for the whole page to only display for certain users (for any unaccepted visitors it will throw a Craft 403 error page), you can add something like this to the top of your template:

{% requirePermission "permissionHandle" %}


(You can find a full list of permissions here.)

I'd recommend the accessCp permission handle if you're wanting to block everyone but the client and admin accounts for Craft Client.