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:Profile Tag

Fetching user data made easy.

Overview

The user:profile tag has access to all of a user's basic data. Passwords and hashes are not available through this tag.

Hot Tip!

This will default to the currently logged in user if none are specified.

Shorthand

You can use user and drop the :profile bit off if you prefer.

Examples

To output the currently logged in user's details, you can do this:

{{ user }}
The current user's name is {{ name }}.
{{ /user }}
<s:user>
The current user's name is {{ $name }}.
</s:user>
 
{{-- Aliasing the user. --}}
<s:user
as="user"
>
The current user's name is {{ $user->name }}.
</s:user>

Or perhaps you'd like to show user profile pages. Assuming your users have a username field, you could create a wildcard route like this:

Route::statamic('users/{username}', 'users.show');

Then when visiting /users/chuck, for example, you could display Chuck's details like this:

{{ user:profile field="username" :value="segment_2" }}
{{ first_name }} {{ last_name }}
{{ /user:profile }}
<s:user:profile
field="username"
:value="$segment_2 ?? null"
>
{{ $first_name }} {{ $last_name }}
</s:user:profile>

Or to find a user by email:

{{ user:profile :email="email" }}
{{ first_name }} {{ last_name }}
{{ /user:profile }}
<s:user:profile
:email="$email"
>
{{ $first_name }} {{ $last_name }}
</s:user:profile>

Parameters

id

string

Fetch user by ID.

email

string

Fetch user by email.

field

string

Fetch user by a specific field value. Used with value below.

value

string

Value of above field to fetch user by.

Variables

Variable Type Description

user data

mixed

All user data (except password) is available.

no_results

boolean

true if user cannot be found or is logged out.

is_[role]

boolean

true if user is assigned a given role. For example, is_admin or is_banned.

in_[group]

boolean

true if user is in a given group. For example, in_admin or in_editors.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →