Debian Codegraph @

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

raw
1 ---
2 title: Type
3 description: Returns the content type of the given page.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: string
9 signatures: [PAGE.Type]
10 ---
11
12 The `Type` method on a `Page` object returns the [content type](g) of the given page. The content type is defined by the `type` field in front matter, or inferred from the top-level directory name if the `type` field in front matter is not defined.
13
14 With this content structure:
15
16 ```tree
17 content/
18 ├── auction/
19 │ ├── _index.md
20 │ ├── item-1.md
21 │ └── item-2.md <-- front matter: type = books
22 ├── books/
23 │ ├── _index.md
24 │ ├── book-1.md
25 │ └── book-2.md
26 ├── films/
27 │ ├── _index.md
28 │ ├── film-1.md
29 │ └── film-2.md
30 └── _index.md
31 ```
32
33 To list the books, regardless of [section](g):
34
35 ```go-html-template
36 {{ range where .Site.RegularPages.ByTitle "Type" "books" }}
37 <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
38 {{ end }}
39 ```
40
41 Hugo renders this to;
42
43 ```html
44 <h2><a href="/books/book-1/">Book 1</a></h2>
45 <h2><a href="/books/book-2/">Book 2</a></h2>
46 <h2><a href="/auction/item-2/">Item 2</a></h2>
47 ```
48
49 The `type` field in front matter is also useful for targeting a template. See [details][].
50
51 [details]: /templates/lookup-order/#target-a-template