diff --git a/content/en/templates/taxonomy-templates.md b/content/en/templates/taxonomy-templates.md index e343df471..43bba4a4a 100644 --- a/content/en/templates/taxonomy-templates.md +++ b/content/en/templates/taxonomy-templates.md @@ -101,12 +101,12 @@ If you need to display custom metadata for each taxonomy term, you will need to ```go-html-template ``` @@ -120,9 +120,9 @@ Taxonomies can be ordered by either alphabetical key or by the number of content ```go-html-template ``` @@ -186,42 +186,38 @@ using the [list templates](/templates/lists/): 3. You can list all terms for a taxonomy 4. You can list all taxonomies (with their terms) -## Display a Single Piece of Content's Taxonomies +## List Terms Assigned to a Page -Within your content templates, you may wish to display the taxonomies that piece of content is assigned to. +List the terms assigned to a page using the `.Page.GetTerms` method. -Because we are leveraging the front matter system to define taxonomies for content, the taxonomies assigned to each content piece are located in the usual place (i.e., `.Params.`). - -### Example: List Tags in a Single Page Template +To render an unordered list: ```go-html-template - {{ end }} ``` -Alternatively, you may use the [delimit template function][delimit] as a shortcut if the taxonomies should just be listed with a separator. See {{< gh 2143 >}} on GitHub for discussion. +To render a comma-delimited list: + +```go-html-template +{{ $taxonomy := "tags" }} +{{ with .GetTerms $taxonomy }} +

+ {{ (site.GetPage $taxonomy).LinkTitle }}: + {{ range $k, $_ := . -}} + {{ if $k }}, {{ end }} + {{ .LinkTitle }} + {{- end }} +

+{{ end }} +``` ## List Content with the Same Taxonomy Term @@ -231,9 +227,9 @@ If you are using a taxonomy for something like a series of posts, you can list i ```go-html-template ``` @@ -245,16 +241,16 @@ This would be very useful in a sidebar as “featured content”. You could even ```go-html-template ``` @@ -270,9 +266,9 @@ The following example displays all terms in a site's tags taxonomy: ```go-html-template ``` @@ -281,28 +277,27 @@ 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 @@ -312,11 +307,11 @@ Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to {{< code file="links-to-all-tags.html" >}} {{ $taxo := "tags" }} {{< /code >}}