Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Custom suggestions hook

No security coverage Under active development

This module provides a way to create custom template suggestions based on existing Drupal hooks. It allows developers to easily define specific template files for different content types or situations by modifying a suggestions array within the theme or module.

The custom_suggestions_hook_theme_suggestions_HOOK_alter is a pre-process function that allows us to easily produce custom template suggestions based on an existing hook. For instance, if we wanted to alter the theme suggestions for all of our Pages, then we could use custom_suggestions_hook_theme_suggestions_page_alter(). We can leverage a $suggestions[] array to produce a number of template suggestions for whichever element we specify in the function’s title. In order to edit the
element in our “custom_suggestions_hook” theme/module, we want to modify the function to the following:

example hook html alter:

/**
 * Implements hook_theme_suggestions_html_alter().
 */
function custom_suggestions_hook_theme_suggestions_html_alter(array &$suggestions, array $variables, $hook)
{
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    $suggestions[] = $hook . '__' . $node->bundle();
  }
}
Drupal 8–10 · not 11

Ask your assistant about Custom suggestions hook

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jul 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.0.2 Stable 8–10 Jul 25, 2023