User — role check
Open in builderThis is a property of the entity itself, so there’s no field name to fill in.
Raw entity
Open in builder (Raw entity)Reads the entity directly, before field formatters run.
- Snippet 1
{% if user.hasRole( 'editor') %} … {% endif %} - 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.