ResourceType

ResourceType 方法

返回給定資源的媒體類型的主要類型。常見的資源類型包括 audioimagetextvideo

範例

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

處理內容檔案時,資源類型為 page

content/
├── lessons/
│   ├── lesson-1/
│   │   ├── _objectives.md  <-- 資源類型 = page
│   │   ├── _topics.md      <-- 資源類型 = page
│   │   ├── _example.jpg    <-- 資源類型 = image
│   │   └── index.md
│   └── _index.md
└── _index.md

使用上述結構,我們可以遍歷 page 類型的頁面資源來構建內容:

{{ range .Resources.ByType "page" }}
  {{ .Content }}
{{ end }}