资源类型
Syntax
RESOURCE.ResourceType
Returns
string
常见的资源类型包括 音频
、 图像
、 文本
和 视频
。
{{ with resources.Get "image/a.jpg" }}
{{ .ResourceType }} → image
{{ .MediaType.MainType }} → image
{{ end }}
处理内容文件时,资源类型为 页面
。
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
使用上述结构,我们可以遍历类型为 页面
的页面资源来构建内容:
layouts/lessons/single.html
{{ range .Resources.ByType "page" }}
{{ .Content }}
{{ end }}