Debian Codegraph @

docs/content/en/methods/page/Data.md

raw
1 ---
2 title: Data
3 description: Returns a unique data object for each page kind.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Data
9 signatures: [PAGE.Data]
10 ---
11
12 The `Data` method on a `Page` object returns a unique data object for each [page kind](g).
13
14 > [!NOTE]
15 > The `Data` method is only useful within [taxonomy](g) and [term](g) templates.
16 >
17 > Themes that are not actively maintained may still use `.Data.Pages` in their templates. Although that syntax remains functional, use one of these methods instead: [`Pages`][], [`RegularPages`][], or [`RegularPagesRecursive`][]
18
19 The examples that follow are based on this project configuration:
20
21 {{< code-toggle file=hugo >}}
22 [taxonomies]
23 genre = 'genres'
24 author = 'authors'
25 {{< /code-toggle >}}
26
27 And this content structure:
28
29 ```tree
30 content/
31 ├── books/
32 │ ├── and-then-there-were-none.md --> genres: suspense
33 │ ├── death-on-the-nile.md --> genres: suspense
34 │ └── jamaica-inn.md --> genres: suspense, romance
35 │ └── pride-and-prejudice.md --> genres: romance
36 └── _index.md
37 ```
38
39 ## In a taxonomy template
40
41 Use these methods on the `Data` object within a _taxonomy_ template.
42
43 `Singular`
44 : (`string`) Returns the singular name of the taxonomy.
45
46 ```go-html-template
47 {{ .Data.Singular }} → genre
48 ```
49
50 `Plural`
51 : (`string`) Returns the plural name of the taxonomy.
52
53 ```go-html-template
54 {{ .Data.Plural }} → genres
55 ```
56
57 `Terms`
58 : (`page.Taxonomy`) Returns the `Taxonomy` object, consisting of a map of terms and the [weighted pages](g) associated with each term.
59
60 ```go-html-template
61 {{ $taxonomyObject := .Data.Terms }}
62 ```
63
64 > [!NOTE]
65 > Once you have captured the `Taxonomy` object, use any of the [taxonomy methods][] to sort, count, or capture a subset of its weighted pages.
66
67 Learn more about [taxonomy templates][].
68
69 ## In a term template
70
71 Use these methods on the `Data` object within a _term_ template.
72
73 `Singular`
74 : (`string`) Returns the singular name of the taxonomy.
75
76 ```go-html-template
77 {{ .Data.Singular }} → genre
78 ```
79
80 `Plural`
81 : (`string`) Returns the plural name of the taxonomy.
82
83 ```go-html-template
84 {{ .Data.Plural }} → genres
85 ```
86
87 `Term`
88 : (`string`) Returns the name of the term.
89
90 ```go-html-template
91 {{ .Data.Term }} → suspense
92 ```
93
94 Learn more about [term templates][].
95
96 [`Pages`]: /methods/page/pages/
97 [`RegularPagesRecursive`]: /methods/page/regularpagesrecursive/
98 [`RegularPages`]: /methods/page/regularpages/
99 [taxonomy methods]: /methods/taxonomy/
100 [taxonomy templates]: /templates/types/#taxonomy
101 [term templates]: /templates/types/#term