mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-17 18:34:41 -04:00
Document taxonomies Page method
This commit is contained in:
parent
05494b7d2c
commit
3aa75ee740
26
content/en/methods/taxonomy/Page.md
Normal file
26
content/en/methods/taxonomy/Page.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
title: Page
|
||||||
|
description: Returns the taxonomy page or nil if the taxonomy has no terms.
|
||||||
|
categories: []
|
||||||
|
keywords: []
|
||||||
|
action:
|
||||||
|
related: []
|
||||||
|
returnType: page.Page
|
||||||
|
signatures: [TAXONOMY.Page]
|
||||||
|
---
|
||||||
|
|
||||||
|
{{< new-in 0.125.0 >}}
|
||||||
|
|
||||||
|
This `TAXONOMY` method returns nil if the taxonomy has no terms, so you must code defensively:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ with .Site.Taxonomies.tags.Page }}
|
||||||
|
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is rendered to:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<a href="/tags/">Tags</a>
|
||||||
|
```
|
@ -36,24 +36,8 @@ See [Template Lookup](/templates/lookup-order/).
|
|||||||
|
|
||||||
### Taxonomy methods
|
### Taxonomy methods
|
||||||
|
|
||||||
A Taxonomy is a `map[string]WeightedPages`.
|
{{< list-pages-in-section path=/methods/taxonomy/ >}}
|
||||||
|
|
||||||
.Get TERM
|
|
||||||
: Returns the WeightedPages for a given term. For example: ;
|
|
||||||
`site.Taxonomies.tags.Get "tag-a"`.
|
|
||||||
|
|
||||||
.Count TERM
|
|
||||||
: The number of pieces of content assigned to the given term. For example: \
|
|
||||||
`site.Taxonomies.tags.Count "tag-a"`.
|
|
||||||
|
|
||||||
.Alphabetical
|
|
||||||
: Returns an OrderedTaxonomy (slice) ordered by term.
|
|
||||||
|
|
||||||
.ByCount
|
|
||||||
: Returns an OrderedTaxonomy (slice) ordered by number of entries.
|
|
||||||
|
|
||||||
.Reverse
|
|
||||||
: Returns an OrderedTaxonomy (slice) in reverse order. Must be used with an OrderedTaxonomy.
|
|
||||||
|
|
||||||
### OrderedTaxonomy
|
### OrderedTaxonomy
|
||||||
|
|
||||||
@ -273,14 +257,20 @@ The following example displays all terms in a site's tags taxonomy:
|
|||||||
This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms.
|
This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms.
|
||||||
|
|
||||||
{{< code file=layouts/partials/all-taxonomies.html >}}
|
{{< code file=layouts/partials/all-taxonomies.html >}}
|
||||||
<ul>
|
{{ with .Site.Taxonomies }}
|
||||||
{{ range $taxonomy, $terms := site.Taxonomies }}
|
{{ $numberOfTerms := 0 }}
|
||||||
<li>
|
{{ range $taxonomy, $terms := . }}
|
||||||
{{ with site.GetPage $taxonomy }}
|
{{ $numberOfTerms = len . | add $numberOfTerms }}
|
||||||
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if gt $numberOfTerms 0 }}
|
||||||
<ul>
|
<ul>
|
||||||
{{ range $term, $weightedPages := $terms }}
|
{{ range $taxonomy, $terms := . }}
|
||||||
|
{{ with $terms }}
|
||||||
|
<li>
|
||||||
|
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||||
|
<ul>
|
||||||
|
{{ range $term, $weightedPages := . }}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||||
<ul>
|
<ul>
|
||||||
@ -293,7 +283,10 @@ This example will list all taxonomies and their terms, as well as all the conten
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
{{< /code >}}
|
{{< /code >}}
|
||||||
|
|
||||||
## `.Site.GetPage` for taxonomies
|
## `.Site.GetPage` for taxonomies
|
||||||
|
Loading…
x
Reference in New Issue
Block a user