hugo/docs/content/en/methods/resource/ResourceType.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.1 KiB

title description categories keywords action
ResourceType Returns the main type of the given resource's media type.
related returnType signatures
string
RESOURCE.ResourceType

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.md

With the structure above, we can range through page resources of type page to build content:

{{< code file=layouts/lessons/single.html >}} {{ range .Resources.ByType "page" }} {{ .Content }} {{ end }} {{< /code >}}

{{% include "methods/resource/_common/global-page-remote-resources.md" %}}