1

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.

2
  • Have you added a theme hook?
    – Eyal
    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. Jan 19, 2016 at 6:28

2 Answers 2

1

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' %}
0

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:

Drupal\Core\Template\Loader\ThemeRegistryLoader

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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