简体   繁体   中英

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 }} {{ 'solutions.description' | trans }} alone shows the content as expected.

What syntax would it be?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM