List pages which share the same parent

Hi there, I have a site structured similar to this.

content
├── _index.md
├── contact.md
├── docs
│   ├── _index.md
│   └── section1
│   │   ├── _index.md
│   │   ├── how
│   │   │   └── index.md
│   │   ├── where
│   │   │   └── index.md
│   │   └── why
│   │       └── index.md
│   └── section2
│       ├── _index.md
│       ├── advanced
│       │   └── index.md
│       └── super-advanced
│           └── index.md
└── help.md

I wish to list pages for navigation based on subsections and to provide a next/prev button for the previous or next page within the subscription.
Ideally, I started with this to list all pages which shares the same parent, so within section1 I should find 3 pages only

<!-- Retrieve the current Parent page -->
{{ $cur := .Parent  }}
<!-- Range across pages where the parent is the same as the actual page -->
{{ range where .Site.Pages.ByWeight ".Parent" "$cur"}}
  {{ .Permalink }}
{{end}}

Although, it returns blank. I tried to change quotes, remote the dot before Parent but nothing.
I tried with this also

{{ $pages := where site.Pages "Parent" .Parent }}
{{ print $pages}}

But the output is

Page(/docs/section1/_index.md) Pages(0)

I feel like I’m complicating stuff with no result. Any direction or idea?

Thanks in advance!

layouts/_default/single.html

  <p>Pages in current section:</p>

  <ul>
    {{ range .CurrentSection.Pages }}
      <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
    {{ end }}
  </ul>

  <p>Previous/Next navigation in current section:</p>

  {{ with .CurrentSection.Pages.Prev . }}
    <a href="{{ .RelPermalink }}">Previous in Section</a>
  {{ end }}

  {{ with .CurrentSection.Pages.Next . }}
    <a href="{{ .RelPermalink }}">Next in Section</a>
  {{ end }}
2 Likes

Isn’t this the same?

{{ with .PrevInSection }}

1 Like

No, they are not the same. Mine has more characters, takes longer to type, and is more difficult to understand.

4 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.