Lab*_*ino 2 php drupal twig drupal-8
我include在Drupal中创建了一个:
{% include directory ~ '/partials/header.html.twig' %}
但我收到此错误:
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).
根据Drupal和Twig文档,我正在以正确的方式进行操作。
我有一个目录partials,一个文件header.html.twig。
我究竟做错了什么?我在El Capitan的MAMP和OSX中运行Drupal。Drupal 8.3.7
在Drupal 8中使用Twig 的include或extends时,必须指定主题/模块命名空间。
这里是Drupal.org的完整解释:https ://www.drupal.org/node/2143557
另外,您应该将局部文件添加到自定义主题的模板文件夹中。这是最佳做法。
使用范例
{% include "@mytheme/partials/favicons.html.twig" %}
Run Code Online (Sandbox Code Playgroud)