I am newbie in Drupal. Using some articles, I have created a child theme of Bartik in Drupal 8 but I do not know how to override default template files. Can anyone help me to understand the child theme structure in Drupal 8?

up vote 3 down vote accepted

In your child theme's folder create a subfolder called "templates". In this folder you should store your own templates. Just copy the system's (or parent theme's) template to your folder and modify it.

Further on, you can create more special templates, i.e. not only node.html.twig but also node--blog.html.twig.

Finally, switch on twig debugging, then you will get comments in your html like this:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--bootasde-branding.html.twig
   x block--system-branding-block.html.twig
   * block--system.html.twig
   * block.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/bootstrap/templates/block/block--system-branding-block.html.twig' -->

Then you always now which template was finally taken.

  • Fine intro for twig debugging is this: drupalize.me/blog/201405/lets-debug-twig-drupal-8 – Rainer Feike Jul 7 '16 at 11:25
  • Hello @rainer thank you for your help. I have created the structure : themes/custom/my_theme/templates and copied page.html.twig from Bartik's template folder. But still my new file is not coming. Data is displaying from Bartik's file only. I have also cleared the cache. – wanna_be_superman Jul 7 '16 at 11:56
  • Have you activated your theme in admin/appearance ? – Rainer Feike Jul 7 '16 at 11:58
  • Yes my child theme is activated. – wanna_be_superman Jul 7 '16 at 12:02
  • It should be working. Does it? What was the problem? – Rainer Feike Jul 8 '16 at 8:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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