Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Bought Jack McDade's course on design. Going through it now...and it is SO well done!

— Justin Jackson, Transistor.fm

User:Can Tag

Anything inside the user:can tag will only be rendered if the user has the specified permission.

Overview

User tags are designed for sites that have areas or features behind a login. The {{ user:can }} tag is used to check if the currently logged in user has a one or more specific permissions.

Example

Let's say we want a link to edit the current entry in the control panel if the user has the edit faq entries permission.

{{ user:can do="edit faq entries" }}
<a href="{{ edit_url }}">Edit this Page</a>
{{ /user:can }}
{{-- Using user methods --}}
@if (auth()->user()?->can('edit blog entries'))
...
@endif
 
{{-- Using Fluent Tags --}}
@if (Statamic::tag('user:can')->do('edit blog entries')->fetch())
...
@endif
 
{{-- Using Antlers Blade Components --}}
<s:user:can
do="edit blog entries"
>
...
</s:user:can>

Super Users

Super users can always do everything, so no matter what you check for — whether it exists as an actual permission or not — it will always return true.

Can’t

We also support the negative use case using {{ user:cant }} tags.

{{ user:cant do="anything" }}
<p>Aww, I'm sure that's not true! 😊</p>
{{ /user:cant }}
{{-- Using user methods --}}
@if (auth()->user()?->cant('do anything'))
<p>Aww, I'm sure that's not true! 😊</p>
@endif
 
{{-- Using Fluent Tags --}}
@if (Statamic::tag('user:cant')->do('anything')->fetch())
<p>Aww, I'm sure that's not true! 😊</p>
@endif
 
{{-- Using Antlers Blade Components --}}
<s:user:cant
do="anything"
>
<p>Aww, I'm sure that's not true! 😊</p>
</s:user:cant>

Permissions List

Check out the the complete list of user permissions.

Parameters

permission|do

string

The permissions to check against. You can use the parameter permission or do, depending on you feel about the grammar of each case. Specify multiple permissions by pipe separating them: {{ user:can do="things|stuff" }}.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →