mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
63
docs/content/en/functions/urls/URLize.md
Normal file
63
docs/content/en/functions/urls/URLize.md
Normal file
@@ -0,0 +1,63 @@
|
||||
---
|
||||
title: urls.URLize
|
||||
description: Returns the given string, sanitized for usage in a URL.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [urlize]
|
||||
related:
|
||||
- functions/urls/Anchorize
|
||||
returnType: string
|
||||
signatures: [urls.URLize INPUT]
|
||||
aliases: [/functions/urlize]
|
||||
---
|
||||
|
||||
{{% include "/functions/urls/_common/anchorize-vs-urlize.md" %}}
|
||||
|
||||
## 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']
|
||||
{{< /code-toggle >}}
|
||||
|
||||
The published site will have this structure:
|
||||
|
||||
```text
|
||||
public/
|
||||
├── authors/
|
||||
│ ├── victor-hugo/
|
||||
│ │ └── index.html
|
||||
│ └── index.html
|
||||
├── books/
|
||||
│ ├── les-miserables/
|
||||
│ │ └── index.html
|
||||
│ └── index.html
|
||||
└── index.html
|
||||
```
|
||||
|
||||
To create a link to the term page:
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomy := "authors" }}
|
||||
{{ $term := "Victor Hugo" }}
|
||||
{{ with index .Site.Taxonomies $taxonomy (urlize $term) }}
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
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
|
Reference in New Issue
Block a user