部分
Syntax
PAGE.Section
Returns
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 }}
但是,如果前题内容中的 type
字段在一个或多个页面上已定义,则基于 Type
的页面集合将不同于基于 Section
的页面集合。