mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
9b0050e9aa
git-subtree-dir: docs git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
1.4 KiB
1.4 KiB
title | description | categories | keywords | action | aliases | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
urls.URLize | Returns the given string, sanitized for usage in a URL. |
|
|
{{% 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:
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:
{{ $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.