Skip to content

Macros

Macros are comparable with functions in regular programming languages. They are useful to reuse template fragments to not repeat yourself.

Importing macros

In order to use a macro you need to import it first.

{% from "@macros/footer_group.twig" import footer_group %}

In this example we imported the footer_group macro defined in footer_group.twig file in @macros namespace and the macro is now available under the footer_group variable.

It is possible to change the variable name form imported macro to something else, for example group:

{% from "@macros/footer_group.twig" import footer_group as group %}

Using macros

When the macro is imported, you can use it in your template.

{{ footer_group(footerGroup) }}

Macros accept input parameters. In this example we pass the footerGroup variable to the macro, which represents the FooterGroup object.