From 310ce949ad0bbcde46f09511be64941420c649f6 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 14 Apr 2023 13:27:16 -0700 Subject: [PATCH] tpl/urls: Add JoinPath template function See https://pkg.go.dev/net/url#JoinPath Closes #9694 --- content/en/functions/urls.JoinPath.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 content/en/functions/urls.JoinPath.md diff --git a/content/en/functions/urls.JoinPath.md b/content/en/functions/urls.JoinPath.md new file mode 100644 index 000000000..c0e0464b6 --- /dev/null +++ b/content/en/functions/urls.JoinPath.md @@ -0,0 +1,24 @@ +--- +title: urls.JoinPath +description: Joins the provided elements into a URL string and cleans the result of any ./ or ../ elements. +categories: [functions] +menu: + docs: + parent: functions +keywords: [urls,path,join] +signature: ["urls.JoinPath ELEMENT..."] +--- + +```go-html-template +{{ urls.JoinPath "" }} → "/" +{{ urls.JoinPath "a" }} → "a" +{{ urls.JoinPath "a" "b" }} → "a/b" +{{ urls.JoinPath "/a" "b" }} → "/a/b" +{{ urls.JoinPath "https://example.org" "b" }} → "https://example.org/b" + +{{ urls.JoinPath (slice "a" "b") }} → "a/b" +``` + +Unlike the [`path.Join`] function, `urls.JoinPath` retains consecutive leading slashes. + +[`path.Join`]: /functions/path.join/