HUGO
Menu
GitHub 90453 stars Mastodon

path.Base

Returns the last element of the given path.
Syntax
path.Base PATH
Returns
string

Usage

The path.Base function returns the last element of the given path. The function removes trailing slashes before it extracts the last element.

On Windows, the function first replaces each backslash (\) in its arguments with a slash (/).

Examples

{{ path.Base "a/news.html" }} → news.html
{{ path.Base "news.html" }} → news.html
{{ path.Base "a/b/c" }} → c
{{ path.Base "/x/y/z/" }} → z

Empty paths and paths that contain only slashes:

{{ path.Base "" }} → .
{{ path.Base "/" }} → /