Debian Codegraph @

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

raw
1 ---
2 title: urls.URLize
3 description: Returns the given string, sanitized for usage in a URL.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [urlize]
9 returnType: string
10 signatures: [urls.URLize INPUT]
11 aliases: [/functions/urlize]
12 ---
13
14 {{% include "/_common/functions/urls/anchorize-vs-urlize.md" %}}
15
16 ## Example
17
18 Use the `urlize` function to create a link to a [term page](g).
19
20 Consider this project configuration:
21
22 {{< code-toggle file=hugo >}}
23 [taxonomies]
24 author = 'authors'
25 {{< /code-toggle >}}
26
27 And this front matter:
28
29 {{< code-toggle file=content/books/les-miserables.md fm=true >}}
30 title = 'Les Misérables'
31 authors = ['Victor Hugo']
32 {{< /code-toggle >}}
33
34 The published site will have this structure:
35
36 ```tree
37 public/
38 ├── authors/
39 │ ├── victor-hugo/
40 │ │ └── index.html
41 │ └── index.html
42 ├── books/
43 │ ├── les-miserables/
44 │ │ └── index.html
45 │ └── index.html
46 └── index.html
47 ```
48
49 To create a link to the term page:
50
51 ```go-html-template
52 {{ $taxonomy := "authors" }}
53 {{ $term := "Victor Hugo" }}
54 {{ with index .Site.Taxonomies $taxonomy (urlize $term) }}
55 <a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
56 {{ end }}
57 ```
58
59 To generate a list of term pages associated with a given content page, use the [`GetTerms`][] method on a `Page` object.
60
61 [`GetTerms`]: /methods/page/getterms/