Problem
I'm not sure if this is an issue with this module or something else. So I am posting this to get assistance. I've added this template suggestion to my theme's .theme file to create a custom template for Layout Builder tabs on a User entity. The template suggestion is based on the label of the Layout Builder tabs section.
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function THEME_theme_suggestions_layout_alter(array &$suggestions, array $variables) {
if($variables['theme_hook_original'] == 'tabs') {
$entity_type = $variables['content']['#entity']->getEntityTypeId();
if($entity_type == 'user') {
$tabs_label = $variables['content']['#settings']['label'];
$suggestions[] = (!empty($tabs_label) ? 'tabs__'.str_replace(' ', '_', strtolower($tabs_label)) : '');
}
}
}
I enabled twig debugging and verified that the template suggestion was registered, but when I create the suggested template in my theme, only tabs.html.twig is utilized. I did verify that placing a tabs.html.twig in the theme will override the module template, but more specific templates seem to be ignored.
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'tabs' -->
<!-- FILE NAME SUGGESTIONS:
* tabs--custom-label.html.twig
x tabs.html.twig
x tabs.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/custom/THEME/templates/tabs.html.twig' -->
I verified that this is an issue on a new Drupal 9.5 install.
Comments
Comment #2
segx commented