DocsSintaxTextTrimtrim_suffix

trim_suffix

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

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

Removes the given suffix once from the end.

Given

{"file": "report.txt"}

Template

{{ file | trim_suffix:'.txt' }}

Result

report
AbsentSource

Leaves the value unchanged when it does not end with the given suffix.

Given

{"file": "report.md"}

Template

{{ file | trim_suffix:'.txt' }}

Result

report.md
ChainedSource

Strips a leading and a trailing slash by piping trim_prefix into trim_suffix.

Given

{"path": "/users/"}

Template

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

Result

users
BasicSource

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

Given

{"input": "Welcome aboard.   "}

Template

{{ input | trim_suffix }}

Result

Welcome aboard.