diff --git a/content/en/templates/taxonomy-templates.md b/content/en/templates/taxonomy-templates.md index d15a6f639..364633cfe 100644 --- a/content/en/templates/taxonomy-templates.md +++ b/content/en/templates/taxonomy-templates.md @@ -66,7 +66,7 @@ A Taxonomy is a `map[string]WeightedPages`. Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order. -``` +```go []struct { Name string WeightedPages WeightedPages @@ -91,7 +91,7 @@ Each element of the slice has: WeightedPages is simply a slice of WeightedPage. -``` +```go type WeightedPages []WeightedPage ``` @@ -103,16 +103,16 @@ type WeightedPages []WeightedPage ## Displaying custom metadata in Taxonomy Terms Templates -If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content///_index.md` and add your metadata in it's front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-meta-data-to-a-taxonomy-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by iterating through the variable `.Pages` as such: +If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content///_index.md` and add your metadata in its front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-meta-data-to-a-taxonomy-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by iterating through the variable `.Pages` as such: -``` +```go-html-template
    - {{ range .Pages }} -
  • - {{ .Title }} - {{ .Params.wikipedia }} -
  • - {{ end }} + {{ range .Pages }} +
  • + {{ .Title }} + {{ .Params.wikipedia }} +
  • + {{ end }}
``` @@ -124,46 +124,46 @@ Taxonomies can be ordered by either alphabetical key or by the number of content ### Order Alphabetically Example -``` +```go-html-template
    - {{ $type := .Type }} - {{ range $key, $value := .Data.Terms.Alphabetical }} - {{ $name := .Name }} - {{ $count := .Count }} - {{ with $.Site.GetPage (printf "/%s/%s" $type $name) }} -
  • {{ $name }} {{ $count }}
  • + {{ $type := .Type }} + {{ range $key, $value := .Data.Terms.Alphabetical }} + {{ $name := .Name }} + {{ $count := .Count }} + {{ with $.Site.GetPage (printf "/%s/%s" $type $name) }} +
  • {{ $name }} {{ $count }}
  • + {{ end }} {{ end }} - {{ end }}
``` ### Order by Popularity Example -``` +```go-html-template
    - {{ $type := .Type }} - {{ range $key, $value := .Data.Terms.ByCount }} - {{ $name := .Name }} - {{ $count := .Count }} - {{ with $.Site.GetPage (printf "/%s/%s" $type $name) }} -
  • {{ $name }} {{ $count }}
  • + {{ $type := .Type }} + {{ range $key, $value := .Data.Terms.ByCount }} + {{ $name := .Name }} + {{ $count := .Count }} + {{ with $.Site.GetPage (printf "/%s/%s" $type $name) }} +
  • {{ $name }} {{ $count }}
  • + {{ end }} {{ end }} - {{ end }}
``` ### Order by Least Popular Example -``` +```go-html-template
    - {{ $type := .Type }} - {{ range $key, $value := .Data.Terms.ByCount.Reverse }} - {{ $name := .Name }} - {{ $count := .Count }} - {{ with $.Site.GetPage (printf "/%s/%s" $type $name) }} -
  • {{ $name }} {{ $count }}
  • + {{ $type := .Type }} + {{ range $key, $value := .Data.Terms.ByCount.Reverse }} + {{ $name := .Name }} + {{ $count := .Count }} + {{ with $.Site.GetPage (printf "/%s/%s" $type $name) }} +
  • {{ $name }} {{ $count }}
  • + {{ end }} {{ end }} - {{ end }}
``` @@ -233,14 +233,14 @@ Because we are leveraging the front matter system to define taxonomies for conte ### Example: List Tags in a Single Page Template -``` +```go-html-template
    - {{ range .Params.tags }} - {{ $name := . }} - {{ with $.Site.GetPage (printf "/tags/%s" $name) }} -
  • {{ $name }}
  • + {{ range .Params.tags }} + {{ $name := . }} + {{ with $.Site.GetPage (printf "/tags/%s" $name) }} +
  • {{ $name }}
  • + {{ end }} {{ end }} - {{ end }}
``` @@ -250,15 +250,15 @@ To list such taxonomies, use the following: ### Example: Comma-delimit Tags in a Single Page Template -``` +```go-html-template {{ if .Params.directors }} - Director{{ if gt (len .Params.directors) 1 }}s{{ end }}: - {{ range $index, $director := .Params.directors }} - {{- if gt $index 0 }}, {{ end -}} - {{ with $.Site.GetPage (printf "/directors/%s" $director) -}} - {{ $director }} - {{- end -}} - {{ end -}} + Director{{ if gt (len .Params.directors) 1 }}s{{ end }}: + {{ range $index, $director := .Params.directors }} + {{- if gt $index 0 }}, {{ end -}} + {{ with $.Site.GetPage (printf "/directors/%s" $director) -}} + {{ $director }} + {{- end -}} + {{ end -}} {{ end }} ``` @@ -270,11 +270,11 @@ If you are using a taxonomy for something like a series of posts, you can list i ### Example: Showing Content in Same Series -``` +```go-html-template ``` @@ -284,14 +284,14 @@ This would be very useful in a sidebar as “featured content”. You could even ### Example: Grouping "Featured" Content -``` +```go-html-template