0

I was listening to a Drupal Developer on youtube and one of the suggestions he has, is that when you go into a template folder, create some subdirectories for easier management, like this:

Templates
->Blocks
->Fields
 ->YourField.html.twig
->Nodes

So I want to do the same thing for my template folder, however when I do that, I get this error:

Twig\Error\LoaderError: Template "modules/custom/task/templates/field--expire-date.html.twig" is not defined.

Now granted, I learned with Drupal that Twig + Theming Templates is different than Twig + Module Templates. I am using my own module.

Is there a way for me to tell Twig there is another subdirectory (Ex: Fields Folder), so it can find the code?

2
  • Clear/Flush all caches.
    – No Sssweat
    May 22, 2019 at 11:25
  • Once again for clarification. You are not in a theme, you are in a custom module?
    – leymannx
    May 22, 2019 at 11:30

1 Answer 1

4

In your "task" module you must have a task_theme function where you've defined your templates. In there you'll need to update with your new paths too. e.g.

This

'template' => "field--expire-date.html.twig"

becomes:

'template' => "fields/field--expire-date.html.twig"
1
  • Thanks a Million Sir! You get a "Your Awesome!" comment! ^_^
    – Shawn
    May 22, 2019 at 16:50

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.