Type
返回给定页面的内容类型。
Syntax
PAGE.Type
Returns
string
Page 对象上的 Type 方法返回给定页面的 内容类型。内容类型由 front matter 中的 type 字段定义,如果 front matter 中未定义 type 字段,则从顶级目录名称推断。
使用此内容结构:
content/
├── auction/
│ ├── _index.md
│ ├── item-1.md
│ └── item-2.md <-- front matter: type = books
├── books/
│ ├── _index.md
│ ├── book-1.md
│ └── book-2.md
├── films/
│ ├── _index.md
│ ├── film-1.md
│ └── film-2.md
└── _index.md要列出书籍,无论 栏目:
{{ range where .Site.RegularPages.ByTitle "Type" "books" }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}Hugo 渲染此内容为:
<h2><a href="/books/book-1/">Book 1</a></h2>
<h2><a href="/books/book-2/">Book 2</a></h2>
<h2><a href="/auction/item-2/">Item 2</a></h2>front matter 中的 type 字段也可用于定位模板。请参阅 详情。