Data

Data


为每种页面类型返回一个唯一的数据对象。

The Data method on a Page object returns a unique data object for each page kind.

Data对象上的方法为每种页面类型Page返回一个唯一的数据对象。

The examples that follow are based on this site configuration:

hugo.
     
taxonomies:
  author: authors
  genre: genres
[taxonomies]
  author = 'authors'
  genre = 'genres'
{
   "taxonomies": {
      "author": "authors",
      "genre": "genres"
   }
}

And this content structure:

content/
├── books/
│   ├── and-then-there-were-none.md --> genres: suspense
│   ├── death-on-the-nile.md        --> genres: suspense
│   └── jamaica-inn.md              --> genres: suspense, romance
│   └── pride-and-prejudice.md      --> genres: romance
└── _index.md

In a taxonomy template #

Use these methods on the Data object within a taxonomy template.

Singular
(string) Returns the singular name of the taxonomy.
{{ .Data.Singular }} → genre
Plural
(string) Returns the plural name of the taxonomy.
{{ .Data.Plural }} → genres
Terms
(page.Taxonomy) Returns the Taxonomy object, consisting of a map of terms and the [weighted pages]associated with each term.
{{ $taxonomyObject := .Data.Terms }} 

Learn more about [taxonomy templates].

In a term template #

Use these methods on the Data object within a term template.

Singular
(string) Returns the singular name of the taxonomy.
{{ .Data.Singular }} → genre
Plural
(string) Returns the plural name of the taxonomy.
{{ .Data.Plural }} → genres
Term
(string) Returns the name of the term.
{{ .Data.Term }} → suspense

Learn more about [term templates].