DocsSintaxTextTrimtrim_prefix

trim_prefix

Removes the given prefix once from the start of a string, returning it unchanged when it does not start with that prefix.

InputArgumentsReturnsstringstringstringstringno argumentsstring[]bytestring[]byte[]byteno arguments[]byte
Source
BasicSource

Removes the given prefix once from the start.

Given

{"path": "/api/users"}

Template

{{ path | trim_prefix:'/api' }}

Result

/users
AbsentSource

Leaves the value unchanged when it does not start with the given prefix.

Given

{"path": "api/v1/users"}

Template

{{ path | trim_prefix:'/' }}

Result

api/v1/users
Matched onceSource

Removes the prefix a single time, so a repeated leading segment is only stripped once.

Given

{"path": "//api"}

Template

{{ path | trim_prefix:'/' }}

Result

/api
BasicSource

Strips leading whitespace when trim_prefix is called without an argument, leaving trailing whitespace in place.

Given

{"input": "   Welcome aboard."}

Template

{{ input | trim_prefix }}

Result

Welcome aboard.