Debian Codegraph @

docs/content/en/methods/resource/ResourceType.md

raw
1 ---
2 title: ResourceType
3 description: Returns the main type of the given resource's media type.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: string
9 signatures: [RESOURCE.ResourceType]
10 ---
11
12 {{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
13
14 Common resource types include `audio`, `image`, `text`, and `video`.
15
16 ```go-html-template
17 {{ with resources.Get "image/a.jpg" }}
18 {{ .ResourceType }} → image
19 {{ .MediaType.MainType }} → image
20 {{ end }}
21 ```
22
23 When working with content files, the resource type is `page`.
24
25 ```tree
26 content/
27 ├── lessons/
28 │ ├── lesson-1/
29 │ │ ├── _objectives.md <-- resource type = page
30 │ │ ├── _topics.md <-- resource type = page
31 │ │ ├── _example.jpg <-- resource type = image
32 │ │ └── index.md
33 │ └── _index.md
34 └── _index.md
35 ```
36
37 With the structure above, we can range through page resources of type `page` to build content:
38
39 ```go-html-template {file="layouts/lessons/page.html"}
40 {{ range .Resources.ByType "page" }}
41 {{ .Content }}
42 {{ end }}
43 ```