replace Filter

Replace all occurrences of a substring with a string.

Parameters

Parameter Required Description
search Yes string String to replace.
replacement Yes string Replacement string.

Category

String Filters

Description

The replace filter replaces all occurrences of a given substring with a string. The first argument is the substring to search for, and the second argument is the replacement string for all matches of the search string.

{{ "What is bad is bad." | replace: 'bad', 'good' }}

Output

What is good is good.

If you want to replace just the first occurrence of a substring, use the replace_first filter instead.