类型
Syntax
PAGE.Type
Returns
string
Page
对象上的 Type
方法返回给定页面的 内容类型 。内容类型由前置内容中的 type
字段定义,如果前置内容中未定义 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>
前置内容中的 type
字段也可用于定位模板。参见 详情 。