function hook_preprocess_HOOK

Same name in other branches
  1. 7.x modules/system/theme.api.php \hook_preprocess_HOOK()
  2. 9 core/lib/Drupal/Core/Render/theme.api.php \hook_preprocess_HOOK()
  3. 8.9.x core/lib/Drupal/Core/Render/theme.api.php \hook_preprocess_HOOK()
  4. 11.x core/lib/Drupal/Core/Render/theme.api.php \hook_preprocess_HOOK()

Preprocess theme variables for a specific theme hook.

This hook allows modules to preprocess theme variables for a specific theme hook. It should only be used if a module needs to override or add to the theme preprocessing for a theme hook it didn't define.

For more detailed information, see the Theme system overview topic.

Parameters

$variables: The variables array (modify in place).

Related topics

272 functions implement hook_preprocess_HOOK()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

claro_preprocess_admin_block in core/themes/claro/claro.theme
Implements template_preprocess_HOOK() for admin_block.
claro_preprocess_admin_block_content in core/themes/claro/claro.theme
Implements template_preprocess_HOOK() for admin_block.
claro_preprocess_block in core/themes/claro/claro.theme
Implements hook_preprocess_block() for block content.
claro_preprocess_block_content_add_list in core/themes/claro/claro.theme
Implements template_preprocess_HOOK() for block_content_add_list.
claro_preprocess_datetime_wrapper in core/themes/claro/claro.theme
Implements template_preprocess_HOOK() for datetime_wrapper.

... See full list

File

core/lib/Drupal/Core/Render/theme.api.php, line 605

Code

function hook_preprocess_HOOK(&$variables) {
    // This example is from node_preprocess_html(). It adds the node type to
    // the body classes, when on an individual node page or node preview page.
    if (($node = \Drupal::routeMatch()->getParameter('node')) || ($node = \Drupal::routeMatch()->getParameter('node_preview'))) {
        if ($node instanceof NodeInterface) {
            $variables['node_type'] = $node->getType();
        }
    }
}

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