function hook_theme_suggestions_HOOK_alter

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/theme.api.php \hook_theme_suggestions_HOOK_alter()
  2. 10 core/lib/Drupal/Core/Render/theme.api.php \hook_theme_suggestions_HOOK_alter()
  3. 11.x core/lib/Drupal/Core/Render/theme.api.php \hook_theme_suggestions_HOOK_alter()

Alters named suggestions for a specific theme hook.

This hook allows any module or theme to provide alternative theme function or template name suggestions and reorder or remove suggestions provided by hook_theme_suggestions_HOOK() or by earlier invocations of this hook.

HOOK is the least-specific version of the hook being called. For example, if '#theme' => 'node__article' is called, then node_theme_suggestions_node() will be invoked, not node_theme_suggestions_node__article(). The specific hook called (in this case 'node__article') is available in $variables['theme_hook_original'].

Implementations of this hook must be placed in *.module or *.theme files, or must otherwise make sure that the hook implementation is available at any given time.

@todo Add @code sample.

Parameters

array $suggestions: An array of theme suggestions.

array $variables: An array of variables passed to the theme hook. Note that this hook is invoked before any preprocessing.

See also

hook_theme_suggestions_alter()

hook_theme_suggestions_HOOK()

Related topics

16 functions implement hook_theme_suggestions_HOOK_alter()

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

bartik_theme_suggestions_form_alter in core/themes/bartik/bartik.theme
Implements hook_theme_suggestions_HOOK_alter() for form templates.
claro_theme_suggestions_details_alter in core/themes/claro/claro.theme
Implements hook_theme_suggestions_HOOK_alter() for details.
claro_theme_suggestions_form_element_alter in core/themes/claro/claro.theme
Implements hook_theme_suggestions_HOOK_alter() for form_element.
layout_builder_theme_suggestions_field_alter in core/modules/layout_builder/layout_builder.module
Implements hook_theme_suggestions_HOOK_alter().
test_legacy_theme_theme_suggestions_theme_test_function_suggestions_alter in core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.theme
Implements hook_theme_suggestions_HOOK_alter().

... See full list

File

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

Code

function hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) {
    if (empty($variables['header'])) {
        $suggestions[] = 'hookname__no_header';
    }
}

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