HUGO
Menu
GitHub 90498 stars Mastodon

Type

Returns the content type of the given page.
Syntax
PAGE.Type
Returns
string

Usage

The Type method on a Page object returns the content type 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. For pages in the root of the content directory, the content type is page unless defined in front matter.

Set the type field in front matter to group pages from different sections, or to target a specific template.

Examples

This example lists the books regardless of section, using this content structure:

content/
├── auction/
│   ├── _index.md
│   ├── item-1.md
│   └── item-2.md  <-- front matter: type = books
├── books/
│   ├── _index.md
│   ├── book-1.md
│   └── book-2.md
├── films/
│   ├── _index.md
│   ├── film-1.md
│   └── film-2.md
└── _index.md
{{ range where site.RegularPages.ByTitle "Type" "books" }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}

The rendered HTML:

<h2><a href="/books/book-1/">Book 1</a></h2>
<h2><a href="/books/book-2/">Book 2</a></h2>
<h2><a href="/auction/item-2/">Item 2</a></h2>