类型
语法
PAGE.Type
返回
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
字段对于定位模板也很有用。 请参阅详细信息。