Drupal 9: Theme Hook To Add User Template Suggestions

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function THEME_theme_suggestions_user_alter(array &$suggestions, array $variables) {
  // Get the view mode.
  $mode = $variables['elements']['#view_mode'];

  // Create a theme hook suggestion which has the view mode name in it.
  $suggestions[] = 'user__' . $mode;
}

Create theme templates with in the following way.

user--<view mode>.html.twig

 

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
3 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.