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 字段也可用於定位模板。請參閱 詳情。