Search code examples
symfonytwigtwig-filter

Twig: how to apply a filter to a translation string


Lets say I have this:

{%trans%}html.string{%endtrans%}

that prints this string

This is a string with some <i>html</i> tags.

I want to apply the Twig filter striptags to obtain this:

This is a string with some html tags.

As you can see I have "removed" the italic tags.

So I need a way to do something like:

{%trans%}html.string|striptags{%endtrans%}

Obviously this is not the correct way of applying filters to the translated string, so, how can I do this?


Solution

  • {{"html.string"|trans|striptags}}
    

    note that you always have to apply the trans filter first.