Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Make twig macros available across multiple component partials.

0
by mjauvin, last modified on June 25th, 2025

In your plugin, create a views/twig folder and add a file named macros.htm in this folder.

{% macro myMacro(vars) %}
    {# do something with vars #}
{% endmacro %}

In your components partials, use this to make the macros available:

{% import "author.plugin::twig.macros" as macros %}

{# you can now use macros.myMacro(_context) #}

Note: the _context argument passes the variables visible from the calling partial.

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?