function template_preprocess_user

Same name in other branches
  1. 9 core/modules/user/user.module \template_preprocess_user()
  2. 10 core/modules/user/user.module \template_preprocess_user()
  3. 11.x core/modules/user/user.module \template_preprocess_user()

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 1486

Code

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];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.