Created
October 27, 2014 13:51
-
-
Save tentacode/9728963b9f3a714608f3 to your computer and use it in GitHub Desktop.
Calling twig macro dynamically with twig "attribute" method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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> #} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro type_1(value) %} | |
<p>Type One {{ value }}</p> | |
{% endmacro %} | |
{% macro type_2(value) %} | |
<p>Type Two {{ value }}</p> | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an other solution since Twig 2 ?