1

I'm having a bit of a hard time with Drupal 8.

I've created a custom theme and am trying to override twig files. I've got debugging enabled so I know which files to copy to my template directory. However, when I copy a twig template it outputs nothing.

For example, I'm trying to wrap the site title in an H1 element. The core template file used in this case is /core/themes/stable/templates/block/block--system-branding-block.html.twig. If I add the H1 element in that file the header is inside a H1 element, but when I copy the twig file to my template directory the whole header is gone.

I can see in the source code that the file was found:

<!--  BEGIN OUTPUT from 'themes/mytheme/block--system-branding-block.html.twig' -->
<!--  END OUTPUT from 'themes/mytheme/block--system-branding-block.html.twig' -->

The documentation suggests that copying the relevant twig file is all that's needed but maybe I'm missing something? And if this should work, how can I debug this issue (the Apache error log doesn't report any errors).

  • Did you flush/clear the cache? – No Sssweat Feb 7 '17 at 2:12
2

Yes, to override twig file you just need to have the twig file with filename suggestion you get with debugger.

In case you are not able to see it, make sure of following:-

  • Your custom theme is enabled.
  • Folder where you kept your twig file has right permission.
  • Clear your Drupal caches.
  • 1
    Thank you. I think it may have been a permissions issue. Just tried copying / changing the twig file again with a fresh pair of eyes, and this time I also rebuild my install's directory and file permissions... and it now works as expected. (The twig file's permissions are 640, with me as the owner and www-data as the group owner). – rkhff Feb 7 '17 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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