trim_prefix
Removes the given prefix once from the start of a string, returning it unchanged when it does not start with that prefix.
InputArgumentsReturns
Sourcestringstringstringstringno argumentsstring[]bytestring[]byte[]byteno arguments[]byteBasicSource
Removes the given prefix once from the start.
Given
{"path": "/api/users"}Template
{{ path | trim_prefix:'/api' }}Result
/usersAbsentSource
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/usersMatched onceSource
Removes the prefix a single time, so a repeated leading segment is only stripped once.
Given
{"path": "//api"}Template
{{ path | trim_prefix:'/' }}Result
/apiBasicSource
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.