Reputation: 7249
I have some string which has multiple words and between them there is always ', ' but also on end
str = ['str1, str2, str3, ']
I need to do
str|replace(...)
but with condition to remove only last set of character
', '
All this I need to do in twig not in Controller
Upvotes: 0
Views: 482
Reputation: 572
You can use trim:
{% set str = ['foo, bar, foobar, '] %}
{{ str[0]|trim(', ') }}
//Outputs 'foo, bar, foobar'
Upvotes: 1