In Drupal theme folder structure, there is written:

Templates provide HTML markup and some presentation logic. Contrary to Drupal 7, in Drupal 8 template files (*.html.twig files) must be stored in the 'templates' subfolder.

In my theme, I have a styleguide folder at the root. Drupal 9 finds template files, such as mytheme/styleguide/components/10-atoms/form/input.html.twig, in this folder.

Drupal 9 will use this input.html.twig file despite it's not in the mytheme/templates folder.

  • 1
    Yes, normally Drupal looks for Twig files in the templates subfolder, but there are several ways to change that. For example in a hook_theme or in an alternative Twig file loader like drupal.org/project/components – 4k4 Oct 15 '20 at 15:25
  • I just don't understand why Drupal find suggestion ouside the templates folder in the theme. – Gilles Oct 19 '20 at 7:17
  • Can you tell a bit more about mytheme, which base theme, content of the info file or other details that might be important. Do you have any modules installed that might be related? – 4k4 Oct 19 '20 at 9:55
  • With a fresh installation, my twig template isn't in the templates folder & it's working. But I'm using a styleguide folder in the theme & I don't want Drupal to use it on his own. I just want it to use those in the (bartikssen/)templates folder. <!-- THEME DEBUG --> <!-- THEME HOOK: 'page' --> <!-- FILE NAME SUGGESTIONS: * page--front.html.twig * page--node.html.twig x page.html.twig --> <!-- BEGIN OUTPUT from 'themes/bartikssen/page.html.twig' --> – Gilles Nov 9 '20 at 10:44

Ok, I have found a solution, I just need to add in my settings.php the "styleguide" folder in the ignore directories

$settings['file_scan_ignore_directories'] = [

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.