How do I replace ";" with "," in string "Red; Green; Blue"?
{% set rgb = "Red; Green; Blue" %}
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityTwig has a replace filter for that. You can replace strings/vars with strings/vars:
{% set string = "I love apples" %}
{% set var = "like" %}
{% set string = string|replace({'apples': 'kiwis', 'love': var}) %}
{{ string }} {# Prints "I like kiwis" #}
Your example:
{% set rgb = "Red; Green; Blue" %}
{% set rgb = rgb|replace({';': ','}) %}
{{ rgb }} {# Prints "Red, Green, Blue" #}
|replace('apples', 'kiwis')
– Brandon Kelly
Jun 14 '14 at 13:35