HUGO
Menu
GitHub 87548 stars Mastodon

ResourceType

返回给定资源的媒体类型的主类型。

Syntax

RESOURCE.ResourceType

Returns

string

此方法可用于 全局资源页面资源远程资源

常见的资源类型包括 audioimagetextvideo

{{ with resources.Get "image/a.jpg" }}
  {{ .ResourceType }} → image
  {{ .MediaType.MainType }} → image
{{ end }}

当使用内容文件时,资源类型是 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

在上面的结构中,我们可以遍历 page 类型的页面资源来构建内容:

layouts/lessons/page.html
{{ range .Resources.ByType "page" }}
  {{ .Content }}
{{ end }}

Last updated: January 1, 0001
Improve this page