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

---
要使用该方法，你必须先通过 [`Get`][] 或 [`Canonical`][] 方法，从页面的 [`OutputFormats`][] 集合中选出特定的 [output format](g)（输出格式）。

## 示例

```go-html-template
{{ with .Site.Home.OutputFormats.Get "rss" }}
  {{ with .MediaType }}
    {{ .Type }} → application/rss+xml
    {{ .MainType }} → application
    {{ .SubType }} → rss
    {{ .Suffixes }} → [rss]
    {{ .FirstSuffix.Suffix }} → rss
  {{ end }}
{{ end }}
```

## 方法

在 `MediaType` 对象上使用这些方法。

`Type`
: (`string`) 返回媒体类型。

`MainType`
: (`string`) 返回媒体类型的主类型。

`SubType`
: (`string`) 返回媒体类型的子类型。

`Suffixes`
: (`slice`) 返回媒体类型可能的文件后缀切片。

`FirstSuffix.Suffix`
: (`string`) 返回媒体类型可能的文件后缀中的第一个。

[`Canonical`]: /methods/page/outputformats/#canonical
[`Get`]: /methods/page/outputformats/#get
[`OutputFormats`]: /methods/page/outputformats/

