2014-05-27 22:32:57 +00:00
---
2014-05-29 22:42:05 +00:00
aliases:
- /indexes/lists/
- /doc/indexes/
- /extras/indexes
2016-01-06 22:45:19 +00:00
lastmod: 2015-09-15
2014-05-29 22:42:05 +00:00
date: 2014-05-21
linktitle: Taxonomy Terms
2014-05-27 22:32:57 +00:00
menu:
main:
2014-05-29 22:42:05 +00:00
parent: layout
next: /templates/views
prev: /templates/homepage
title: Taxonomy Terms Template
weight: 60
2015-05-22 18:46:09 +00:00
toc: true
2014-05-27 22:32:57 +00:00
---
A unique template is needed to create a list of the terms for a given
taxonomy. This is different from the [list template ](/templates/list/ )
2015-01-29 19:34:56 +00:00
as that template is a list of content, whereas this is a list of meta data.
2014-05-27 22:32:57 +00:00
2016-11-21 12:02:02 +00:00
Note that a taxonomy terms page can also have a content file with frontmatter, see [Source Organization ]({{< relref "overview/source-directory.md#content-for-home-page-and-other-list-pages" >}} ).
2014-05-27 22:32:57 +00:00
## Which Template will be rendered?
Hugo uses a set of rules to figure out which template to use when
rendering a specific page.
2015-01-29 19:34:56 +00:00
A Taxonomy Terms List will be rendered at /`PLURAL`/
(e.g. http://spf13.com/topics/)
from the following prioritized list:
* /layouts/taxonomy/`SINGULAR`.terms.html (e.g. `/layouts/taxonomy/topic.terms.html` )
* /layouts/\_default/terms.html
If a file isn’ t present,
2014-09-03 04:12:26 +00:00
then the next one in the list will be used. This enables you to craft
2014-05-27 22:32:57 +00:00
specific layouts when you want to without creating more templates
2015-01-28 02:17:09 +00:00
than necessary. For most sites, only the `_default` file at the end of
2014-05-27 22:32:57 +00:00
the list will be needed.
If that neither file is found in either the /layouts or /theme/layouts
2015-01-28 02:17:09 +00:00
directory, then Hugo will not render the taxonomy terms pages. It is also
2014-05-27 22:32:57 +00:00
common for people to render taxonomy terms lists on other pages such as
the homepage or the sidebar (such as a tag cloud) and not have a
dedicated page for the terms.
2015-01-28 02:17:09 +00:00
2014-05-27 22:32:57 +00:00
## Variables
2016-11-20 22:00:57 +00:00
Taxonomy Terms pages are of the type `Page` and have all the
[page variables ](/templates/variables/ ) and
2015-01-28 02:17:09 +00:00
[site variables ](/templates/variables/ )
available to use in the templates.
2014-05-27 22:32:57 +00:00
Taxonomy Terms pages will additionally have:
2014-09-03 04:12:26 +00:00
* **.Data.Singular** The singular name of the taxonomy
* **.Data.Plural** The plural name of the taxonomy
* **.Data.Terms** The taxonomy itself
* **.Data.Terms.Alphabetical** The Terms alphabetized
* **.Data.Terms.ByCount** The Terms ordered by popularity
2014-05-27 22:32:57 +00:00
2015-05-12 16:46:45 +00:00
The last two can also be reversed: ** .Data.Terms.Alphabetical.Reverse**, ** .Data.Terms.ByCount.Reverse**.
2015-01-28 02:17:09 +00:00
### Example terms.html files
2014-05-27 22:32:57 +00:00
2015-01-28 02:17:09 +00:00
This content template is used for [spf13.com ](http://spf13.com/ ).
2015-01-29 19:34:56 +00:00
It makes use of [partial templates ](/templates/partials/ ). The list of taxonomy
2015-01-28 02:17:09 +00:00
templates cannot use a [content view ](/templates/views/ ) as they don't display the content, but
2014-05-27 22:32:57 +00:00
rather information about the content.
This particular template lists all of the Tags used on
2015-01-28 02:17:09 +00:00
[spf13.com ](http://spf13.com/ ) and provides a count for the number of pieces of
2014-05-27 22:32:57 +00:00
content tagged with each tag.
2015-09-15 18:31:11 +00:00
`.Data.Terms` is a map of terms ⇒ [contents]
2014-05-27 22:32:57 +00:00
2014-06-06 20:15:19 +00:00
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
2014-05-27 22:32:57 +00:00
< section id = "main" >
< div >
2015-01-28 02:17:09 +00:00
< h1 id = "title" > {{ .Title }}< / h1 >
2014-05-27 22:32:57 +00:00
2015-01-28 02:17:09 +00:00
< ul >
{{ $data := .Data }}
2014-05-27 22:32:57 +00:00
{{ range $key, $value := .Data.Terms }}
2016-05-14 04:35:16 +00:00
< li > < a href = "{{ .Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $key | urlize }}" > {{ $key }}< / a > {{ len $value }}< / li >
2014-05-27 22:32:57 +00:00
{{ end }}
< / ul >
< / div >
< / section >
2015-01-31 14:27:42 +00:00
{{ partial "footer.html" . }}
2014-05-27 22:32:57 +00:00
2015-01-28 02:17:09 +00:00
Another example listing the content for each term (ordered by Date):
2014-08-30 03:41:53 +00:00
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
< section id = "main" >
< div >
2015-01-28 02:17:09 +00:00
< h1 id = "title" > {{ .Title }}< / h1 >
2014-08-30 03:41:53 +00:00
{{ $data := .Data }}
{{ range $key,$value := .Data.Terms.ByCount }}
2016-05-14 04:35:16 +00:00
< h2 > < a href = "{{ .Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}" > {{ $value.Name }}< / a > {{ $value.Count }}< / h2 >
2014-08-30 03:41:53 +00:00
< ul >
2015-01-28 02:17:09 +00:00
{{ range $value.Pages.ByDate }}
< li > < a href = "{{ .Permalink }}" > {{ .Title }}< / a > < / li >
{{ end }}
2014-08-30 03:41:53 +00:00
< / ul >
{{ end }}
< / div >
< / section >
2015-01-31 14:27:42 +00:00
{{ partial "footer.html" . }}
2014-08-30 03:41:53 +00:00
2015-01-28 02:17:09 +00:00
2014-05-27 22:32:57 +00:00
## Ordering
2015-01-28 02:17:09 +00:00
Hugo can order the meta data in two different ways. It can be ordered:
2014-05-27 22:32:57 +00:00
2015-01-28 02:17:09 +00:00
* by the number of contents assigned to that key, or
* alphabetically.
2014-05-27 22:32:57 +00:00
2015-01-28 02:17:09 +00:00
### Example terms.html file (alphabetical)
2014-05-27 22:32:57 +00:00
2014-06-06 20:15:19 +00:00
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
2014-05-27 22:32:57 +00:00
< section id = "main" >
< div >
2015-01-28 02:17:09 +00:00
< h1 id = "title" > {{ .Title }}< / h1 >
< ul >
{{ $data := .Data }}
2014-05-27 22:32:57 +00:00
{{ range $key, $value := .Data.Terms.Alphabetical }}
2016-05-14 04:35:16 +00:00
< li > < a href = "{{ .Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}" > {{ $value.Name }}< / a > {{ $value.Count }}< / li >
2014-05-27 22:32:57 +00:00
{{ end }}
2015-01-28 02:17:09 +00:00
< / ul >
2014-05-27 22:32:57 +00:00
< / div >
< / section >
2015-01-31 14:27:42 +00:00
{{ partial "footer.html" . }}
2014-05-27 22:32:57 +00:00
2015-01-28 02:17:09 +00:00
### Example terms.html file (ordered by popularity)
2014-05-27 22:32:57 +00:00
2014-06-06 20:15:19 +00:00
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
2014-05-27 22:32:57 +00:00
< section id = "main" >
< div >
2015-01-28 02:17:09 +00:00
< h1 id = "title" > {{ .Title }}< / h1 >
< ul >
{{ $data := .Data }}
2014-05-27 22:32:57 +00:00
{{ range $key, $value := .Data.Terms.ByCount }}
2016-05-14 04:35:16 +00:00
< li > < a href = "{{ .Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}" > {{ $value.Name }}< / a > {{ $value.Count }}< / li >
2014-05-27 22:32:57 +00:00
{{ end }}
2015-01-28 02:17:09 +00:00
< / ul >
2014-05-27 22:32:57 +00:00
< / div >
< / section >
2015-01-31 14:27:42 +00:00
{{ partial "footer.html" . }}