树枝打印到根块

时间:2017-03-17 11:06:21

标签: twig

有一个名为index.html.twig的模板定义了这些块:

{% block additional %}{% endblock %}

{% block body %}
  {{ macros.renderModule(modules) }}
{% endblock %}

其中macros.renderModule是一个自定义宏,递归渲染模块。

每个模块模板(<type>.html.twig)都像这样扩展base.html.twig

{% extends '::/modules/base.html.twig' %} 

从a <type>.html.twig开始,我想打印到additional块,这是“root”。如果我将块移动到base..html.twig它可以工作,因为每种类型直接扩展»base«。

如何打印到根目录中定义的块?

更新

由于评论,这里有一点说明:

1.:

+base.html.twig      //root
|
+--+index.html.twig //extends base.html.twig and
                    //defines a block »additional«
                    //starts the recursive call »macros.renderModule(…)«
                    //those calls use the templates shows below
2.:

+modules/base.html.twig      //base for each module
|
+--+modules/<type>.html.twig //extends modules/base.html.twig
                             //special template for each »type« of module
                             //**************
                             //PRINT TO block »additional«,
                             //defined in index.html.twig
                             //**************

这些模块的递归调用的宏看起来像是:

{% macro renderModule (modules) %}
  {% import _self as macros %}
  {% for module in modules %}
    {% include '::/modules/' ~ module.type ~ '.html.twig' with {module: module} %}
  {% endfor %}
{% endmacro %}

0 个答案:

没有答案