From 3aa75ee740b4c954866c8768bd85f9b75388a454 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Tue, 16 Apr 2024 08:30:18 -0700 Subject: [PATCH] Document taxonomies Page method --- content/en/methods/taxonomy/Page.md | 26 +++++++++++ content/en/templates/taxonomy-templates.md | 53 ++++++++++------------ 2 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 content/en/methods/taxonomy/Page.md diff --git a/content/en/methods/taxonomy/Page.md b/content/en/methods/taxonomy/Page.md new file mode 100644 index 000000000..e148ac5c7 --- /dev/null +++ b/content/en/methods/taxonomy/Page.md @@ -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 }} + {{ .LinkTitle }} +{{ end }} +``` + +This is rendered to: + +```html +Tags +``` diff --git a/content/en/templates/taxonomy-templates.md b/content/en/templates/taxonomy-templates.md index fa51d6eb4..374d353dd 100644 --- a/content/en/templates/taxonomy-templates.md +++ b/content/en/templates/taxonomy-templates.md @@ -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 >}} - +{{ end }} {{< /code >}} ## `.Site.GetPage` for taxonomies