Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

This course is the most refreshing take on teaching design that I've come across.

— Mikaël Sévigny, Developer

Users Tag

The users tag can be used to fetch, filter, and iterate over Users and their data.

Overview

The Users tag works very much like the Collection Tag. It fetches, filters, sorts, groups, and manipulates lists of your users so you can do whatever you want with them.

A simple example is to loop through all the users and list them by name:

<ul>
{{ users }}
<li>{{ name }}</li>
{{ /users }}
</ul>
<ul>
<s:users>
<li>{{ $name }}</li>
</s:users>
</ul>

Filtering

You can filter you users by group, role, field, or even custom filter class if you need extra control.

Conditions

Want to avoid listing users who have the words "hipster" and "coffee" in their bio?

{{ users bio:doesnt_contain="hipster" bio:doesnt_contain="coffee" }}
<s:users
bio:doesnt_contain="hipster"
bio:doesnt_contain="coffee"
>
...
</s:users>

There are a whole pile of conditions available to you, like :is, :isnt, :contains, :starts_with, and :is_before. Check out this page dedicated to conditions.

Custom Query Scopes

Doing something custom or complicated? You can create query scopes to narrow down those results with the query_scope or filter parameter:

{{ users query_scope="your_query_scope" }}
<s:users
query_scope="your_query_scope"
>
...
</s:users>

Examples

Only super users

{{ users super:is="true" }}
// these people are powerful
{{ /users }}
<s:users
super:is="true"
>
// these people are powerful
</s:users>

Exclude users with gmail email address

{{ users email:doesnt_end_with="@gmail.com" }}
// cool stuff goes here
{{ /users }}
<s:users
email:doesnt_end_with="@gmail.com"
>
// cool stuff goes here
</s:users>

Parameters

group

string

The user group or groups to filter by. You may specify multiple groups by pipe separating them: {{ users group="jocks|geeks" }}.

role

string

The role or roles to filter by. You may specify multiple roles by pipe separating them: {{ users role="author|editor" }}.

sort

string

Sort users by field name (or random). You may pipe-separate multiple fields for sub-sorting and specify sort direction of each field using a colon. For example, sort="title" or sort="date:asc|title:desc" to sort by date then by title.

limit

integer

Limit the total results returned.

filter|query_scope

string

Apply a custom query scope

offset

integer

Skip a specified number of results.

as

string

Alias your entries into a new variable loop.

scope

string

Scope your entries with a variable prefix.

Variables

Variable Type Description

first

boolean

Is this the first item in the loop?

last

boolean

Is this the last item in the loop?

count

integer

The number/index of current iteration in the loop, starting from 1

index

integer

The number/index of current iteration in the loop, starting from 0

no_results

boolean

Returns true if there are no results.

total_results

integer

The total number of results in the loop when there are results. You should use no_results to check if any results exist.

user data

mixed

Each result has access to all the variables inside that entry (name, email, etc).

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →