Does any one know how Drupal 8 picks up theme template file? I mean in source code.

I have module which use a custom template file for a custom block , but the custom template file was not been picked up.

I have tried many different ways, but none working, so I have decided to looking Drupal 8 source code to find out , but I am unable to find out exact source code that picks up the theme template file.

  • Have you added a theme hook?
    – Eyal
    Commented Jan 19, 2016 at 6:18
  • Please check the values on render array that you return from your hook_theme, make sure the twig file is inside the /templates directory of you r module, and flush cache. Commented Jan 19, 2016 at 6:28

2 Answers 2


I had a similar problem and tried:

{% include 'my-template.html.twig' %}
{% include directory ~ '/templates/my-template.html.twig' %}

but ThemeRegistryLoader wouldn't recognize 'my-template'. This syntax worked:

{% include 'modules/custom/my_module/templates/my-template.html.twig' %}

Ok, I have just uninstall / re install the module, now it worked. Drupal 8, probably keep some old information somewhere in cache.

By the way, during debuging, I have found this interesting class:


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.