HUGO
Menu
GitHub 87548 stars Mastodon

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 的页面集合不同。


Last updated: January 1, 0001
Improve this page