Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. user.module

function 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:

    • #user: A \Drupal\user\Entity\User object. The user account of the profile being viewed.
  • attributes: HTML attributes for the containing element.

File

core/modules/user/user.module, line 763

Code

function template_preprocess_user(&$variables) : void {
    $variables['user'] = $variables['elements']['#user'];
    // Helpful $content variable for templates.
    foreach (Element::children($variables['elements']) as $key) {
        $variables['content'][$key] = $variables['elements'][$key];
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal