Remove the '\' from a string in twig

10.9k Views Asked by At

I have this text :

Ch d\`Arnb

Now I want to remove all \ from string if exist. I try a lot of solutions, one of this : {{ item|replace({'\/': ''}) }}. But without success. What can I try next?

1

There are 1 best solutions below

0
On

There is an error in the replace parameter. You are presently trying to remove the / char. Try this:

{% set item = 'Foo\Bar' %}

{{ item|replace({'\\': ''}) }}

Output: FooBar