Section

假設有以下內容結構:

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 }}

然而,如果在一些頁面中定義了 type 字段,基於 Type 的頁面集合將會與基於 Section 的頁面集合有所不同。