ResourceType
- Syntax
- RESOURCE.ResourceType
- Returns
- string
This works with global resources, page resources, and remote resources.
Common resource types include audio, image, text, and video.
{{ with resources.Get "image/a.jpg" }}
{{ .ResourceType }} → image
{{ .MediaType.MainType }} → image
{{ end }}When working with content files, the resource type is page.
content/
├── lessons/
│ ├── lesson-1/
│ │ ├── _objectives.md <-- resource type = page
│ │ ├── _topics.md <-- resource type = page
│ │ ├── _example.jpg <-- resource type = image
│ │ └── index.md
│ └── _index.md
└── _index.mdWith the structure above, we can range through page resources of type page to build content:
{{ range .Resources.ByType "page" }}
{{ .Content }}
{{ end }}Front matter is optional for page resources with resource type page. If you omit front matter, Hugo examines the first non-whitespace characters of the file to determine whether the file begins with front matter. Hugo treats the file as having front matter if it begins with any of these characters:
+(TOML)-(YAML){(JSON)#+(Emacs Org Mode)
If a page resource without front matter begins with one of these characters, Hugo either fails the build or treats some or all of the content as front matter.
To begin the content with one of these characters, such as a Markdown list item or thematic break, include front matter delimiters without any fields:
---
---
- Item 1
- Item 2