Search code examples
phpsymfonytwigtwig-extension

Twig include : use translation in the passed argument


This works fine

{% include 'site/snippet.html.twig'
    with {'description': 'Some text'}
%}

But how to get this to work? Using a translation as argument

{% include 'site/snippet.html.twig'
    with {'description': '{{ 'solutions.description' | trans }}'}
%}

The snippet.html content is:

<p>
    {{ description }}
</p>

And calling the translation {{ 'solutions.description' | trans }} alone shows the content as expected.

What syntax would it be?


Solution

  • You don't need to wrap the string in an extra set of {{ }}. Actually it should work like:

    with {'description': 'solutions.description'|trans}