我已经在Twig中添加了一个宏,并且我正在尝试让这个宏调用它自己。现在看来,使用_self似乎不太受欢迎,而且不起作用,返回错误:
using the dot notation on an instance of Twig_Template is deprecated since version 1.28 and won't be supported anymore in 2.0.如果我确实将_self作为x导入,那么当我最初调用宏时,它就会工作:
{% import _self as twigdebug %}
{{ twigdebug.recursiveTree() }}但是我不能使用_self或twigdebug.recursiveTree递归调用宏。
有没有办法做到这一点?
发布于 2017-01-02 19:40:42
示例:
{% macro recursiveCategory(category) %}
{% import _self as self %}
<li>
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4>
{% if category.children|length %}
<ul>
{% for child in category.children %}
{{ self.recursiveCategory(child) }}
{% endfor %}
</ul>
{% endif %}
</li>
{% endmacro %}
{% from _self import recursiveCategory %}
<div id="categories">
<ul>
{% for category in categories %}
{{ recursiveCategory(category) }}
{% endfor %}
</ul>
</div>https://stackoverflow.com/questions/40707461
复制相似问题