2017-07-31 59 views
2

我有一个宏树枝位于/my-module/templates/menu_macros.html.twig其中看起来像。你应该如何在drupal 8注册一个宏树枝?

{# /my-module/templates/menu-macros.twig #} 
    {# Handles making of the anchor #} 
    {% macro anchor(linkUrl, value) %} 
    <a href="{{ linkUrl }}"> 
     {{ value }} 
    </a> 
    {% endmacro %} 

,然后在我的模板目录我的模块/模板/运动型subnav.menu.html.twig

{% block subnav %} 
{% import "menu-macros.html.twig" as _macro %} 
{% endblock %} 

这将引发错误

Twig_Error_Loader: Template "menu-macros.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "menu-macros.html.twig" in the Drupal theme registry.) in "modules/custom/my-module/templates/sport-subnav.html.twig" at line 11. in Twig_Loader_Chain->getCacheKey() (line 129 of /tmp/local/vendor/twig/twig/lib/Twig/Loader/Chain.php). 

我只是希望它导入我的宏!

+1

读取错误:文件名为'menu_macros.html.twig'您导入'菜单macros.html.twig' –

+0

抱歉,这不是复制和粘贴。错字只在这里。无论哪种方式,我明白了。 “@”用作指向您的回购指标。 '{%import“@ my-module/menu-macros.html.twig”as _macro%}' –

回答

0

{% import "@my-module/menu-macros.html.twig" as _macro %}