# ResourceType
> 返回给定资源媒体类型的主类型。
- 官方英文原文：https://gohugo.io/methods/resource/resourcetype/
- 本页规范地址：https://hugozh.cn/methods/resource/resourcetype/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：RESOURCE.ResourceType
- 返回类型：string
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
> [!NOTE]
> 该方法可用于全局资源、页面资源或远程资源。

常见的资源类型包括 `audio`、`image`、`text` 和 `video`。

```go-html-template
{{ with resources.Get "image/a.jpg" }}
  {{ .ResourceType }} → image
  {{ .MediaType.MainType }} → image
{{ end }}
```

处理内容文件时，资源类型为 `page`。

```tree
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
```

用上面的结构，可以遍历类型为 `page` 的页面资源来构建内容：

```go-html-template {file="layouts/lessons/page.html"}
{{ range .Resources.ByType "page" }}
  {{ .Content }}
{{ end }}
```

