title: Dynamically call a macro in Twig?
body: <p>Is possible to <strong>dynamically call a macro</strong> in Twig? For example, here is a template and a macro named "group" which builds a button group using <code>buttons</code> <code>array</code> argument. There are also two other macros, <code>save</code> and <code>delete</code>, for building save and delete buttons.</p>
  
  <pre><code>{# Make a group of buttons #}
  {% macro group(buttons) %}
  {% spaceless %}
      {% import "::macros.html.twig" as macros %}
  
      {% set content = '' %}
  
      {% for button in buttons %}
          {% set content = content ~ button %}
      {% endfor %}
  
      {{ macros.el('div', content, { 'class' : 'btn-group' }) }}
  {% endspaceless %}
  {% endmacro %}
  
  {# Make a save button #}
  {% macro save(attributes, size, image) %}
  {% spaceless %}
      {{ _self.primary('save'|trans({}, 'buttons'), attributes, size, image) }}
  {% endspaceless %}
  {% endmacro %}
  
  {# Make a delete button #}
  {% macro delete(attributes, size, image) %}
  {% spaceless %}
      {{ _self.danger('delete'|trans({}, 'buttons'), attributes, size, image) }}
  {% endspaceless %}
  {% endmacro %}
  </code></pre>
  
  <p>This works fine passing an <code>array</code> of buttons:</p>
  
  <pre><code>{% import "::buttons.html.twig" as buttons %}
  {% set items = [buttons.save, buttons.delete] %}
  {{ buttons.group(items) }}
  </code></pre>
  
  <p>But i'd like to <strong>pass macro names</strong> to <code>group</code> macro:</p>
  
  <pre><code>{% import "::buttons.html.twig" as buttons %}
  {{ buttons.group(['save', 'delete']) }}
  </code></pre>
  
  <p>and get <code>save</code> and <code>delete</code> macros called automatically. Is this possible and how?</p>