0

I created a custom theme that has the bootstrap_barrio contrib theme as base theme. Everything is setup and working except that my custom region--content.html.twig in the /templates folder of my custom theme isn't being picked up. Drupal continues to use the base region--nowrap.html.twig that came with bootstrap_barrio. My custom template shows up in the list of template suggestions when twig debugging is on.

I thought all I needed to do to override a base template was create a custom template into the custom theme, rebuild cache and Drupal will pick it up, as long as it conforms to the theme hook suggestions naming convention.

Twig Debugging Output:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'region' -->
<!-- FILE NAME SUGGESTIONS:
   x region--nowrap.html.twig
   * region--content.html.twig
   * region.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/contrib/bootstrap_barrio/templates/layout/region--nowrap.html.twig' -->
2
  • Please share the full list of theme suggestions. It could be that your custom template is not specific enough. To test this, copy the exact same template region--nowrap.html.twig from bootstrap_barrio into your theme, modify it with a "I AM HERE" text or something, rebuild caches, and see if Drupal picks it up. Commented Mar 9, 2021 at 2:21
  • @PatrickKenny Done. When I copy same base region--nowrap.html.twig into custom theme, Drupal does pick it up. It just doesn't do the same for region--content.html.twig
    – okey_on
    Commented Mar 9, 2021 at 9:36

2 Answers 2

2

I found a solution to this problem. Apparently if you have active "Clean wrapper for (x region)" on your theme, it will use that damn nowrap template no matter what. Disabling that goes back to use your default theme templates. You can find it over: /admin/appearance/settings/themeName Screenshot to follow: enter image description here

1

The x in the twig debugging indicates the active template. Twig always goes from most specific (top of list) to least specific (bottom of list). So, for this order:

<!-- FILE NAME SUGGESTIONS:
   x region--nowrap.html.twig
   * region--content.html.twig
   * region.html.twig
-->

If region--nowrap.html.twig is present in the current theme or any of the parent themes, it will be given priority over any of the "lower" files.

In your case, You can confirm this by renaming region--nowrap.html.twig in the parent theme; this should cause region--content.html.twig in your subtheme to be given priority.

Solution: Override region--nowrap.html.twig, not region--content.html.twig.

2
  • Thing is: region--nowrap.html.twig is used as the generic template across all regions, though I don't see how it conforms to theme naming-suggestions. There's no region actually named "nowrap", so I don't understand why region--nowrap.html.twig is the preferred by Drupal. Overriding region--nowrap.html.twig will affect all regions than the "content" region I'm trying to affect
    – okey_on
    Commented Mar 9, 2021 at 10:00
  • @okey_on This is probably an issue with Barrio then. I downloaded Barrio 5.1 and checked the region--nowrap.html.twig, which states in the header Bartik's theme implementation to display a header region. So devs just cut-and-paste this file from Bartik. According to the comment, that region should be applied to the header only, not every region on the page. As noted in that comment, use of this template is controlled by hook_preprocess_region(). You can find bootstrap_barrio_preprocess_region() in bootstrap_barrio.theme. Commented Mar 9, 2021 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.