doutan8506 2017-09-30 15:54
浏览 141

Twig_Error_Loader:模板未定义 - Drupal

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.

enter image description here

What am I doing wrong? I am running Drupal in MAMP and OSX, El Capitan. Drupal 8.3.7

  • 写回答

1条回答 默认 最新

  • dongshan9338 2017-10-04 09:06
    关注

    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" %}
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗