0

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?

1 Answer 1

3

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 know which template was finally taken.

6
  • Fine intro for twig debugging is this: drupalize.me/blog/201405/lets-debug-twig-drupal-8 Commented Jul 7, 2016 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. Commented Jul 7, 2016 at 11:56
  • Have you activated your theme in admin/appearance ? Commented Jul 7, 2016 at 11:58
  • Yes my child theme is activated. Commented Jul 7, 2016 at 12:02
  • It should be working. Does it? What was the problem? Commented Jul 8, 2016 at 8:49

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.