path.Join
Returns the shortest path name equivalent to the given path elements joined into a single path.
- Syntax
- path.Join ELEMENT...
- Returns
- string
Usage
The path.Join function returns the shortest path name equivalent to the given path elements joined into a single path. The function adds a slash between elements where needed, then cleans the result as described in the path.Clean function. The function ignores empty elements. If every element is empty, the function returns an empty string.
On Windows, the function first replaces each backslash (\) in its arguments with a slash (/).
Unlike the urls.JoinPath function, path.Join removes consecutive leading slashes.
Arguments
ELEMENT- (
sliceorstring) One or more path elements. If you pass a slice, the function joins each element of the slice.
Examples
{{ path.Join "partial" "news.html" }} → partial/news.html
{{ path.Join "partial/" "news.html" }} → partial/news.html
{{ path.Join "foo/bar" "baz" }} → foo/bar/baz
{{ path.Join "foo" "bar" "baz" }} → foo/bar/bazElements that are empty or that refer to the current or parent directory:
{{ path.Join "foo" "" "baz" }} → foo/baz
{{ path.Join "foo" "." "baz" }} → foo/baz
{{ path.Join "foo" ".." "baz" }} → baz
{{ path.Join "/.." "foo" ".." "baz" }} → /bazJoining the elements of a slice:
{{ path.Join (slice "a" "b") "c" }} → a/b/cLast updated:
November 12, 2026
:
content: Apply style guide to path functions (0fd00f291)
Improve this page