HUGO
Menu
GitHub 90498 stars Mastodon

path.Ext

Returns the file extension of the given path.
Syntax
path.Ext PATH
Returns
string

Usage

The path.Ext function returns the file extension of the given path. The extension is the suffix that begins at the final dot in the last slash-separated element of the path. If the last element does not contain a dot, the function returns an empty string.

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

Examples

{{ path.Ext "a/b/c/news.html" }} → .html
{{ path.Ext "archive.tar.gz" }} → .gz
{{ path.Ext ".gitignore" }} → .gitignore

Paths without a dot in the last element:

{{ path.Ext "a/b/c/news" }} → "" (empty string)
{{ path.Ext "a.b/c" }} → "" (empty string)