Twig: how to apply a filter to a translation string

2.6k Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER
{{"html.string"|trans|striptags}}

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