章节
语法
PAGE.Section
返回
string
使用此内容结构
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
的页面集合不同。