template_preprocess_user

template_preprocess_user(&$variables)

Prepares variables for user templates.

Default template: user.html.twig.

Parameters

array $variables: An associative array containing:

  • elements: An associative array containing the user information and any fields attached to the user. Properties used:
  • attributes: HTML attributes for the containing element.

File

core/modules/user/user.module, line 1420
Enables the user registration and login system.

Code

1
2
3
4
5
6
7
function template_preprocess_user(&$variables) {
  $variables['user'] = $variables['elements']['#user'];
  // Helpful $content variable for templates.
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.