Skip to content
Twig Field Finder
Theme

User — role check

Open in builder

This is a property of the entity itself, so there’s no field name to fill in.

Reads the entity directly, before field formatters run.

  1. Snippet 1
    {% if user.hasRole('editor') %}
      …
    {% endif %}
  2. Snippet 2
    {{ user.getRoles()|join(', ') }}

Gotcha

Outside user.html.twig, user is the default template variable for the current visitor, not an author. Roles are machine names, such as administrator.