-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tpl/urls: Add JoinPath template function
See https://pkg.go.dev/net/url#JoinPath Closes #9694
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters