How button_primary macro can call button macro in Twig engine? I’ve tried
this solution, but it doesn’t work, it says that the function “button” does not exist:
{% macro button(label, type, size) %}
{% set type = type|default('default') %}
{% set size = size|default('large') %}
{% set cls = ['btn'] %}
<a href="#" class="{{ cls|join(' ') }}">{{ label }}</a>
{% endmacro %}
{% macro button_primary(label, size) %}
{{ button(label, 'primary', size) }}
{% endmacro %}
EDIT: As per cr4zydeejay’s answer Feb 7th 2021 the answer was updated to reflect the correct way in Twig 3.x
Twig 3.x
https://twig.symfony.com/doc/3.x/tags/macro.html
Twig 2.x
Unfortunatly Gremo’s answer works, but is not the right way to do it.
http://twig.sensiolabs.org/doc/tags/macro.html
Correct way: