replace_first Filter

Replace the first occurrence 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_first filter replaces the first occurrence of a given substring with a replacement string. The first argument is the substring to search for, and the second argument is the replacement string for the first match of the search string.

{{ "What is new isn't new." | replace: 'new', 'good' }}

Output

What is good isn't new.

If you want to replace all occurrences of a substring, use the replace filter instead.