URL.md - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
URL.md (1359B)
---
1 ---
2 title: safe.URL
3 description: Declares the given string as a safe URL or URL substring.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [safeURL]
9 returnType: template.URL
10 signatures: [safe.URL INPUT]
11 aliases: [/functions/safeurl]
12 ---
13
14 ## Introduction
15
16 {{% include "/_common/functions/go-html-template-package.md" %}}
17
18 ## Usage
19
20 Use the `safe.URL` function to encapsulate a known safe URL or URL substring. Schemes other than the following are considered unsafe:
21
22 - `http:`
23 - `https:`
24 - `mailto:`
25
26 Use of this type presents a security risk: the encapsulated content should come from a trusted source, as it will be included verbatim in the template output.
27
28 See the [Go documentation] for details.
29
30 ## Example
31
32 Without a safe declaration:
33
34 ```go-html-template
35 {{ $href := "irc://irc.freenode.net/#golang" }}
36 <a href="{{ $href }}">IRC</a>
37 ```
38
39 Hugo renders the above to:
40
41 ```html
42 <a href="#ZgotmplZ">IRC</a>
43 ```
44
45 > [!note]
46 > `ZgotmplZ` is a special value that indicates that unsafe content reached a CSS or URL context at runtime.
47
48 To declare the string as safe:
49
50 ```go-html-template
51 {{ $href := "irc://irc.freenode.net/#golang" }}
52 <a href="{{ $href | safeURL }}">IRC</a>
53 ```
54
55 Hugo renders the above to:
56
57 ```html
58 <a href="irc://irc.freenode.net/#golang">IRC</a>
59 ```
60
61 [Go documentation]: https://pkg.go.dev/html/template#URL