filename

Returns the base file name from a path, the final path element including its extension.

A trailing slash is ignored, so the last real segment is returned.

InputArgumentsReturnsstringno argumentsstring
Source
BasicSource

Returns the base file name, the final path element including its extension.

Given

{"path": "docs/reports/q1.pdf"}

Template

{{ path | filename }}

Result

q1.pdf
Bare nameSource

Leaves a bare file name unchanged when there is no directory to strip.

Given

{"path": "config.yaml"}

Template

{{ path | filename }}

Result

config.yaml
Trailing slashSource

Ignores a trailing slash and returns the last real segment of the path.

Given

{"path": "docs/reports/"}

Template

{{ path | filename }}

Result

reports
UnicodeSource

Returns the final segment of a multi-byte path untouched.

Given

{"path": "файлы/отчёт.pdf"}

Template

{{ path | filename }}

Result

отчёт.pdf