Skip to content

Conformance Examples 0.1.0 — Transforms: transform-replace_first

replace_first-basic

Replaces only the first occurrence; later matches are untouched.

Template

{{ phrase | replace_first: "world" "Mark" }}

Context

{
    "phrase": "hello world, big world"
}

Output

hello Mark, big world

replace_first-target-absent

If target is not present, output equals input.

Template

{{ phrase | replace_first: "xyz" "abc" }}

Context

{
    "phrase": "hello world"
}

Output

hello world

replace_first-empty-target

Empty target inserts the replacement at index 0.

Template

{{ phrase | replace_first: "" "X" }}

Context

{
    "phrase": "abc"
}

Output

Xabc

replace_first-chained-after-upcase

Composes correctly when input arrives from a prior transform.

Template

{{ phrase | upcase | replace_first: "WORLD" "Mark" }}

Context

{
    "phrase": "world world"
}

Output

Mark WORLD

Source fixture: transforms/transform-replace_first.json