Debian Codegraph @

docs/content/en/functions/urls/AbsURL.md

raw
1 ---
2 title: urls.AbsURL
3 description: Returns an absolute URL.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [absURL]
9 returnType: string
10 signatures: [urls.AbsURL INPUT]
11 aliases: [/functions/absurl]
12 ---
13
14 With multilingual configurations, use the [`urls.AbsLangURL`][] function instead. The URL returned by this function depends on:
15
16 - Whether the input begins with a slash (`/`)
17 - The `baseURL` in your project configuration
18
19 ## Input does not begin with a slash
20
21 If the input does not begin with a slash, the path in the resulting URL will be relative to the `baseURL` in your project configuration.
22
23 With `baseURL = https://example.org/`
24
25 ```go-html-template
26 {{ absURL "" }} → https://example.org/
27 {{ absURL "articles" }} → https://example.org/articles
28 {{ absURL "style.css" }} → https://example.org/style.css
29 ```
30
31 With `baseURL = https://example.org/docs/`
32
33 ```go-html-template
34 {{ absURL "" }} → https://example.org/docs/
35 {{ absURL "articles" }} → https://example.org/docs/articles
36 {{ absURL "style.css" }} → https://example.org/docs/style.css
37 ```
38
39 ## Input begins with a slash
40
41 If the input begins with a slash, the path in the resulting URL will be relative to the protocol+host of the `baseURL` in your project configuration.
42
43 With `baseURL = https://example.org/`
44
45 ```go-html-template
46 {{ absURL "/" }} → https://example.org/
47 {{ absURL "/articles" }} → https://example.org/articles
48 {{ absURL "/style.css" }} → https://example.org/style.css
49 ```
50
51 With `baseURL = https://example.org/docs/`
52
53 ```go-html-template
54 {{ absURL "/" }} → https://example.org/
55 {{ absURL "/articles" }} → https://example.org/articles
56 {{ absURL "/style.css" }} → https://example.org/style.css
57 ```
58
59 > [!NOTE]
60 > As illustrated by the previous example, using a leading slash is rarely desirable and can lead to unexpected outcomes. In nearly all cases, omit the leading slash.
61
62 [`urls.AbsLangURL`]: /functions/urls/abslangurl/