我有一个宏小枝,位于/my-模块/模板/menu_macs.html.twig中,它看起来是这样的。
{# /my-module/templates/menu-macros.twig #}
{# Handles making of the anchor #}
{% macro anchor(linkUrl, value) %}
<a href="{{ linkUrl }}">
{{ value }}
</a>
{% endmacro %}然后在我的模板目录my-module/templates/sport-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).我只想让它导入我的宏!
发布于 2017-08-09 03:04:46
{% import "@my-module/menu-macros.html.twig" as _macro %}
https://stackoverflow.com/questions/45421433
复制相似问题