I’m a beginner in Drupal and I’m having some trouble with creating a subtheme based on the vartheme_bs5 theme. I hope someone can point me in the right direction.
What I Tried:
I created a subtheme and wanted to override a template. Specifically, I created a templates/page/page.html.twig file in my subtheme to override the templates/page/page.html.twig file in the vartheme_bs5 parent theme.
The parent theme’s page.html.twig includes the following line:
{{ include('varbase_components:page') }}
which points to modules/varbase_components/components/pages/page/page.twig
My actual goal is to override the internal logic of the page.twig file, particularly the line:
{% include 'varbase_components:page-header' %}
which points to modules/varbase_components/components/organisms/page-header/page-header.twig
What I Expected:
I expected that by creating the correct template file in my subtheme, I would be able to override the specific part of the parent theme’s template or the module’s template. Specifically, I hoped to override the page-header.twig file so that my changes would be reflected in the final rendered page.
What Actually Happened:
Despite my attempts, the override did not work. I tried several paths in my subtheme’s templates directory to get the override to work, including:
templates/page-header.twig
templates/page/page-header.twig
templates/varbase_components/components/organisms/page-header/page-header.twig
templates/components/organisms/page-header/page-header.twig
None of these attempts were successful.
My Questions:
Am I following the correct path rules for overriding templates in a subtheme?
Is it possible to override Twig files from modules or other themes in a subtheme, or can I only override files from the parent theme?
Is there something fundamental I might be missing in my approach?
Any guidance or suggestions would be greatly appreciated. I’m feeling quite stuck and would love some advice from experienced developers.
Thank you in advance for your help.
qy z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.