github.com/rabbouni145/gg@v0.47.1/docs/content/en/variables/taxonomy.md (about)

     1  ---
     2  title: Taxonomy Variables
     3  linktitle:
     4  description: Taxonomy pages are of type `Page` and have all page-, site-, and list-level variables available to them. However, taxonomy terms templates have additional variables available to their templates.
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  categories: [variables and params]
     9  keywords: [taxonomies,terms]
    10  draft: false
    11  menu:
    12    docs:
    13      parent: "variables"
    14      weight: 30
    15  weight: 30
    16  sections_weight: 30
    17  aliases: []
    18  toc: true
    19  ---
    20  
    21  ## Taxonomy Terms Page Variables
    22  
    23  [Taxonomy terms pages][taxonomytemplates] are of the type `Page` and have the following additional variables.
    24  
    25  For example, the following fields would be available in `layouts/_defaults/terms.html`, depending on how you organize your [taxonomy templates][taxonomytemplates]:
    26  
    27  .Data.Singular
    28  : The singular name of the taxonomy (e.g., `tags => tag`)
    29  
    30  .Data.Plural
    31  : The plural name of the taxonomy (e.g., `tags => tags`)
    32  
    33  .Data.Pages
    34  : The list of pages in the taxonomy
    35  
    36  .Data.Terms
    37  : The taxonomy itself
    38  
    39  .Data.Terms.Alphabetical
    40  : The taxonomy terms alphabetized
    41  
    42  .Data.Terms.ByCount
    43  : The Terms ordered by popularity
    44  
    45  Note that `.Data.Terms.Alphabetical` and `.Data.Terms.ByCount` can also be reversed:
    46  
    47  * `.Data.Terms.Alphabetical.Reverse`
    48  * `.Data.Terms.ByCount.Reverse`
    49  
    50  ## Use `.Site.Taxonomies` Outside of Taxonomy Templates
    51  
    52  The `.Site.Taxonomies` variable holds all the taxonomies defined site-wide. `.Site.Taxonomies` is a map of the taxonomy name to a list of its values (e.g., `"tags" -> ["tag1", "tag2", "tag3"]`). Each value, though, is not a string but rather a *Taxonomy variable*.
    53  
    54  ## The `.Taxonomy` Variable
    55  
    56  The `.Taxonomy` variable, available, for example, as `.Site.Taxonomies.tags`, contains the list of tags (values) and, for each tag, their corresponding content pages.
    57  
    58  ### Example Usage of `.Site.Taxonomies`
    59  
    60  The following [partial template][partials] will list all your site's taxonomies, each of their keys, and all the content assigned to each of the keys. For more examples of how to order and render your taxonomies, see  [Taxonomy Templates][taxonomytemplates].
    61  
    62  {{< code file="all-taxonomies-keys-and-pages.html" download="all-taxonomies-keys-and-pages.html" >}}
    63  <section>
    64    <ul>
    65      {{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
    66        <li><a href="{{ "/" | relLangURL}}{{ $taxonomyname | urlize }}">{{ $taxonomyname }}</a>
    67          <ul>
    68            {{ range $key, $value := $taxonomy }}
    69            <li> {{ $key }} </li>
    70                  <ul>
    71                  {{ range $value.Pages }}
    72                      <li><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
    73                  {{ end }}
    74                  </ul>
    75            {{ end }}
    76          </ul>
    77        </li>
    78      {{ end }}
    79    </ul>
    80  </section>
    81  {{< /code >}}
    82  
    83  [partials]: /templates/partials/
    84  [taxonomytemplates]: /templates/taxonomy-templates/