mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-15 11:44:44 -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
|
||||
|
||||
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
|
||||
|
||||
@ -273,27 +257,36 @@ 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.
|
||||
|
||||
{{< code file=layouts/partials/all-taxonomies.html >}}
|
||||
<ul>
|
||||
{{ range $taxonomy, $terms := site.Taxonomies }}
|
||||
<li>
|
||||
{{ with site.GetPage $taxonomy }}
|
||||
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
|
||||
{{ end }}
|
||||
<ul>
|
||||
{{ range $term, $weightedPages := $terms }}
|
||||
{{ with .Site.Taxonomies }}
|
||||
{{ $numberOfTerms := 0 }}
|
||||
{{ range $taxonomy, $terms := . }}
|
||||
{{ $numberOfTerms = len . | add $numberOfTerms }}
|
||||
{{ end }}
|
||||
|
||||
{{ if gt $numberOfTerms 0 }}
|
||||
<ul>
|
||||
{{ range $taxonomy, $terms := . }}
|
||||
{{ with $terms }}
|
||||
<li>
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
<ul>
|
||||
{{ range $weightedPages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ range $term, $weightedPages := . }}
|
||||
<li>
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
<ul>
|
||||
{{ range $weightedPages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
## `.Site.GetPage` for taxonomies
|
||||
|
Loading…
x
Reference in New Issue
Block a user