RegularPagesRecursive
Syntax
PAGE.RegularPagesRecursive
Returns
page.Pages
RegularPagesRecursive
方法适用于Page
对象上的以下页面类型:home
,section
,taxonomy
和term
。这些页面类型的模板在上下文中接收一个页面集合。
在您的模板中遍历页面集合:
{{ range .RegularPagesRecursive.ByTitle }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
考虑以下内容结构:
content/
├── lessons/
│ ├── lesson-1/
│ │ ├── _index.md
│ │ ├── part-1.md
│ │ └── part-2.md
│ ├── lesson-2/
│ │ ├── resources/
│ │ │ ├── task-list.md
│ │ │ └── worksheet.md
│ │ ├── _index.md
│ │ ├── part-1.md
│ │ └── part-2.md
│ ├── _index.md
│ ├── grading-policy.md
│ └── lesson-plan.md
├── _index.md
├── contact.md
└── legal.md
在渲染首页时,RegularPagesRecursive
方法返回:
contact.md
lessons/grading-policy.md
legal.md
lessons/lesson-plan.md
lessons/lesson-2/part-1.md
lessons/lesson-1/part-1.md
lessons/lesson-2/part-2.md
lessons/lesson-1/part-2.md
lessons/lesson-2/resources/task-list.md
lessons/lesson-2/resources/worksheet.md
在渲染"lessons"页面时,RegularPagesRecursive
方法返回:
lessons/grading-policy.md
lessons/lesson-plan.md
lessons/lesson-2/part-1.md
lessons/lesson-1/part-1.md
lessons/lesson-2/part-2.md
lessons/lesson-1/part-2.md
lessons/lesson-2/resources/task-list.md
lessons/lesson-2/resources/worksheet.md
在渲染"lesson-1"页面时,RegularPagesRecursive
方法返回:
lessons/lesson-1/part-1.md
lessons/lesson-1/part-2.md
在渲染"lesson-2"页面时,RegularPagesRecursive
方法返回:
lessons/lesson-2/part-1.md
lessons/lesson-2/part-2.md
lessons/lesson-2/resources/task-list.md
lessons/lesson-2/resources/worksheet.md