Reputation: 3960
I created an include
in Drupal:
{% include directory ~ '/partials/header.html.twig' %}
but I am getting this error:
Twig_Error_Loader: Template "themes/custom/mytheme/partials/header.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "themes/custom/mytheme/partials/header.html.twig" in the Drupal theme registry.) in "themes/custom/mytheme/page--front.html.twig" at line 1. in Twig_Loader_Chain->getCacheKey() (line 115 of vendor/twig/twig/lib/Twig/Loader/Chain.php).
According to Drupal and Twig documentation, I am doing it the right way.
I have a directory called partials
and a file called header.html.twig
.
What am I doing wrong? I am running Drupal in MAMP and OSX, El Capitan. Drupal 8.3.7
Upvotes: 2
Views: 14862
Reputation: 1514
When using the include
or extends
of Twig with Drupal 8, you have to specify the theme/modules namespace.
Here the complete explanation from Drupal.org: https://www.drupal.org/node/2143557
Plus, you should add your partials files into the templates folder of your custom theme. It's a best practice.
Usage example
{% include "@mytheme/partials/favicons.html.twig" %}
Upvotes: 8