2019-10-21 04:22:28 -04:00
|
|
|
---
|
2023-10-20 03:42:39 -04:00
|
|
|
title: urls.URLize
|
2023-12-04 09:14:18 -05:00
|
|
|
description: Returns the given string, sanitized for usage in a URL.
|
|
|
|
categories: []
|
2023-10-20 03:42:39 -04:00
|
|
|
keywords: []
|
2023-12-04 09:14:18 -05:00
|
|
|
action:
|
2023-10-20 03:42:39 -04:00
|
|
|
aliases: [urlize]
|
2023-12-04 09:14:18 -05:00
|
|
|
related:
|
|
|
|
- functions/urls/Anchorize
|
2023-10-20 03:42:39 -04:00
|
|
|
returnType: string
|
|
|
|
signatures: [urls.URLize INPUT]
|
|
|
|
aliases: [/functions/urlize]
|
2019-10-21 04:22:28 -04:00
|
|
|
---
|
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
{{% include "/functions/urls/_common/anchorize-vs-urlize.md" %}}
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
## Example
|
|
|
|
|
|
|
|
Use the `urlize` function to create a link to a [term] page.
|
|
|
|
|
|
|
|
Consider this site configuration:
|
|
|
|
|
|
|
|
{{< code-toggle file=hugo >}}
|
|
|
|
[taxonomies]
|
|
|
|
author = 'authors'
|
|
|
|
{{< /code-toggle >}}
|
|
|
|
|
|
|
|
And this front matter:
|
|
|
|
|
|
|
|
{{< code-toggle file=content/books/les-miserables.md fm=true >}}
|
|
|
|
title = 'Les Misérables'
|
|
|
|
authors = ['Victor Hugo']
|
2023-05-22 10:43:12 -04:00
|
|
|
{{< /code-toggle >}}
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
The published site will have this structure:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
```text
|
|
|
|
public/
|
|
|
|
├── authors/
|
|
|
|
│ ├── victor-hugo/
|
|
|
|
│ │ └── index.html
|
|
|
|
│ └── index.html
|
|
|
|
├── books/
|
|
|
|
│ ├── les-miserables/
|
|
|
|
│ │ └── index.html
|
|
|
|
│ └── index.html
|
|
|
|
└── index.html
|
|
|
|
```
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
To create a link to the term page:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
```go-html-template
|
|
|
|
{{ $taxonomy := "authors" }}
|
|
|
|
{{ $term := "Victor Hugo" }}
|
|
|
|
{{ with index .Site.Taxonomies $taxonomy (urlize $term) }}
|
|
|
|
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
|
|
|
{{ end }}
|
2023-05-22 10:43:12 -04:00
|
|
|
```
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2023-12-04 09:14:18 -05:00
|
|
|
To generate a list of term pages associated with a given content page, use the [`GetTerms`] method on a `Page` object.
|
|
|
|
|
|
|
|
[`GetTerms`]: /methods/page/getterms/
|
|
|
|
[term]: /getting-started/glossary/#term
|