I created a module that contains a large number of custom templates. They are only used for the module’s output; they don’t override any existing template file.
I would like to place these templates in sub-directories inside the templates directory.
If I place a template in a sub-directory and set a block’s #theme
to 'account/list_block'
, for example, the block isn’t rendered, but I don’t get errors.
When I keep the template in the sub-directory but set #theme
to 'list_block'
, I get the following error.
Template "modules/contrib/mymodule/templates/list-block.html.twig" is not defined (DrupalCoreTemplateLoaderThemeRegistryLoader: Unable to find template "modules/contrib/mymodule/templates/list-block.html.twig" in the Drupal theme registry.).
From the first example, it seems that Drupal knows the template exists and where to find it, but it doesn’t render it.
Is using sub-directories in the "templates" directory possible?
Sponsored by SupremePR