Skip to content

Instantly share code, notes, and snippets.

@tentacode
Created October 27, 2014 13:51
Show Gist options
  • Save tentacode/9728963b9f3a714608f3 to your computer and use it in GitHub Desktop.
Save tentacode/9728963b9f3a714608f3 to your computer and use it in GitHub Desktop.
Calling twig macro dynamically with twig "attribute" method
{% import 'macro.html.twig' as macro %}
{{ attribute(macro, 'type_1', 'Foobar') }} {# <p>Type One Foobar</p> #}
{{ attribute(macro, 'type_2', 'Barfoo') }} {# <p>Type Two Barfoo</p> #}
{% macro type_1(value) %}
<p>Type One {{ value }}</p>
{% endmacro %}
{% macro type_2(value) %}
<p>Type Two {{ value }}</p>
{% endmacro %}
@Webarkitekt
Copy link

Is there an other solution since Twig 2 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment