Section
返回給定頁面所在的頂級欄目的名稱。
Syntax
PAGE.Section
Returns
string
section(節)是頂級內容目錄或任何包�?_index.md 文件的內容目錄�
使用此內容結構:
content/
├── lessons/
│ ├── math/
│ │ ├── _index.md
│ │ ├── lesson-1.md
│ │ └── lesson-2.md
│ └── _index.md
└── _index.md渲染 lesson-1.md 時:
{{ .Section }} → lessons在上面的示例中,“lessons” 是頂級欄目。
Section 方法通常與 where 函數一起使用來構建頁面集合。
{{ range where .Site.RegularPages "Section" "lessons" }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}這類似於將 Type 方法與 where 函數一起使用
{{ range where .Site.RegularPages "Type" "lessons" }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}但是,如果 front matter 中的 type 字段已在一個或多個頁面上定義,則基於 Type 的頁面集合將與基於 Section 的頁面集合不同。