M. Fritzsche M. Fritzsche - 1 month ago 91
Twig Question

Symfony 3 using a macro in a macro?

i want to use a macro in a macro. But how is this working?


  1. macro in my twig:

    {% import _self as formSubmacros %}

    {% macro printSubcategoriesRow(SubcategoriesForm) %}
    <div class="the content of the subcatecories">

    </div>
    {% endmacro %}

  2. macro i write just under the first and here i want to get the 1 macro in:

    {% import _self as formMacros %}

    {% macro printCategoriesRow(CategoriesForm) %}
    <div class="the content of the categories with the macro subcategories">



    {% for SubcategoriesForm in CategoriesForm.subcategories %}
    {{ formSubmacros.printSubcategoriesRow(SubcategoriesForm) }}
    {% endfor %}



    </div>
    {% endmacro %}



But this is not working...

Answer Source

You should put the import into your macro, to get the proper scope. If this is not working, please provide the error message