hugo/docs/content/en/methods/page/FirstSection.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.7 KiB

title description categories keywords action
FirstSection Returns the Page object of the top level section of which the given page is a descendant.
related returnType signatures
methods/page/Ancestors
methods/page/CurrentSection
methods/page/InSection
methods/page/IsAncestor
methods/page/IsDescendant
methods/page/Parent
methods/page/Sections
page.Page
PAGE.FirstSection

{{% include "methods/page/_common/definition-of-section.md" %}}

{{% note %}} When called on the home page, the FirstSection method returns the Page object of the home page itself. {{% /note %}}

Consider this content structure:

content/
├── auctions/
│   ├── 2023-11/
│   │   ├── _index.md     <-- first section: auctions
│   │   ├── auction-1.md
│   │   └── auction-2.md  <-- first section: auctions
│   ├── 2023-12/
│   │   ├── _index.md     
│   │   ├── auction-3.md
│   │   └── auction-4.md
│   ├── _index.md         <-- first section: auctions
│   ├── bidding.md
│   └── payment.md        <-- first section: auctions
├── books/
│   ├── _index.md         <-- first section: books
│   ├── book-1.md
│   └── book-2.md         <-- first section: books
├── films/
│   ├── _index.md         <-- first section: films
│   ├── film-1.md
│   └── film-2.md         <-- first section: films
└── _index.md             <-- first section: home

To link to the top level section of which the current page is a descendant:

<a href="{{ .FirstSection.RelPermalink }}">{{ .FirstSection.LinkTitle }}</a>