Debian Codegraph @

docs/content/en/methods/page/Pages.md

raw
1 ---
2 title: Pages
3 description: Returns a collection of regular pages within the current section, and section pages of immediate descendant sections.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Pages
9 signatures: [PAGE.Pages]
10 ---
11
12 The `Pages` method on a `Page` object is available to these [page kinds](g): `home`, `section`, `taxonomy`, and `term`. The templates for these page kinds receive a page [collection](g) in [context](g), in the [default sort order](g).
13
14 Range through the page collection in your template:
15
16 ```go-html-template
17 {{ range .Pages.ByTitle }}
18 <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
19 {{ end }}
20 ```
21
22 Consider this content structure:
23
24 ```tree
25 content/
26 ├── lessons/
27 │ ├── lesson-1/
28 │ │ ├── _index.md
29 │ │ ├── part-1.md
30 │ │ └── part-2.md
31 │ ├── lesson-2/
32 │ │ ├── resources/
33 │ │ │ ├── task-list.md
34 │ │ │ └── worksheet.md
35 │ │ ├── _index.md
36 │ │ ├── part-1.md
37 │ │ └── part-2.md
38 │ ├── _index.md
39 │ ├── grading-policy.md
40 │ └── lesson-plan.md
41 ├── _index.md
42 ├── contact.md
43 └── legal.md
44 ```
45
46 When rendering the home page, the `Pages` method returns:
47
48 contact.md
49 legal.md
50 lessons/_index.md
51
52 When rendering the lessons page, the `Pages` method returns:
53
54 lessons/grading-policy.md
55 lessons/lesson-plan.md
56 lessons/lesson-1/_index.md
57 lessons/lesson-2/_index.md
58
59 When rendering lesson-1, the `Pages` method returns:
60
61 lessons/lesson-1/part-1.md
62 lessons/lesson-1/part-2.md
63
64 When rendering lesson-2, the `Pages` method returns:
65
66 lessons/lesson-2/part-1.md
67 lessons/lesson-2/part-2.md
68 lessons/lesson-2/resources/task-list.md
69 lessons/lesson-2/resources/worksheet.md
70
71 In the last example, the collection includes pages in the resources subdirectory. That directory is not a [section](g)---it does not contain an&nbsp;`_index.md`&nbsp;file. Its contents are part of the lesson-2 section.
72
73 > [!NOTE]
74 > When used with a `Site` object, the `Pages` method recursively returns all pages within the site. See [details][].
75
76 ```go-html-template
77 {{ range .Site.Pages.ByTitle }}
78 <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
79 {{ end }}
80 ```
81
82 [details]: /methods/site/pages/