aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/content/en/methods/page/Data.md
blob: 4eccde6ff44ba233992db432d11cbe9c6645d65d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: Data
description: Returns a unique data object for each page kind.
categories: []
keywords: []
action:
  related: []
  returnType: page.Data
  signatures: [PAGE.Data]
toc: true
---

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

[page kind]: /getting-started/glossary/#page-kind

{{% note %}}
The `Data` method is only useful within [taxonomy] and [term] templates.

Themes that are not actively maintained may still use `.Data.Pages` in list templates. Although that syntax remains functional, use one of these methods instead: [`Pages`], [`RegularPages`], or [`RegularPagesRecursive`]

[`Pages`]: /methods/page/pages/
[`RegularPages`]: /methods/page/regularpages/
[`RegularPagesRecursive`]: /methods/page/regularpagesrecursive/
[term]: /getting-started/glossary/#term
[taxonomy]: /getting-started/glossary/#taxonomy
{{% /note %}}

The examples that follow are based on this site configuration:

{{< code-toggle file=hugo >}}
[taxonomies]
genre = 'genres'
author = 'authors'
{{< /code-toggle >}}

And this content structure:

```text
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.

```go-html-template
{{ .Data.Singular }} → genre
```

Plural
: (`string`) Returns the plural name of the taxonomy.

```go-html-template
{{ .Data.Plural }} → genres
```

Terms
: (`page.Taxonomy`) Returns the taxonomy object, consisting of a map of terms and the [weighted pages] associated with each term.

```go-html-template
{{ $taxonomyObject := .Data.Terms }} 
```

{{% note %}}
Once you have captured the taxonomy object, use any of the [taxonomy methods] to sort, count, or capture a subset of its weighted pages.

[taxonomy methods]: /methods/taxonomy
{{% /note %}}

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.

```go-html-template
{{ .Data.Singular }} → genre
```

Plural
: (`string`) Returns the plural name of the taxonomy.

```go-html-template
{{ .Data.Plural }} → genres
```

Term
: (`string`) Returns the name of the term.

```go-html-template
{{ .Data.Term }} → suspense
```

Learn more about [term templates].

[taxonomy templates]: /templates/taxonomy-templates/
[term templates]: /templates/taxonomy-templates/
[weighted pages]: /getting-started/glossary/#weighted-page