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 Use the `urlize` function to create a link to a [term page](g).
17
18 Consider this project configuration:
19
20 {{< code-toggle file=hugo >}}
21 [taxonomies]
22 author = 'authors'
23 {{< /code-toggle >}}
24
25 And this front matter:
26
27 {{< code-toggle file=content/books/les-miserables.md fm=true >}}
28 title = 'Les Misérables'
29 authors = ['Victor Hugo']
30 {{< /code-toggle >}}
31
32 The published site will have this structure:
33
34 ```tree
35 public/
36 ├── authors/
37 │ ├── victor-hugo/
38 │ │ └── index.html
39 │ └── index.html
40 ├── books/
41 │ ├── les-miserables/
42 │ │ └── index.html
43 │ └── index.html
44 └── index.html
45 ```
46
47 To create a link to the term page:
48
49 ```go-html-template
50 {{ $taxonomy := "authors" }}
51 {{ $term := "Victor Hugo" }}
52 {{ with index .Site.Taxonomies $taxonomy (urlize $term) }}
53 <a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
54 {{ end }}
55 ```
56
57 To generate a list of term pages associated with a given content page, use the [`GetTerms`][] method on a `Page` object.
58
59 [`GetTerms`]: /methods/page/getterms/