HUGO

List all sibling pages in a section including _index

A site has many sections and I’d like to have a partial that outputs a list of all sibling pages within that current section. Each section has an _index.md but this page isn’t a listing page its just another sibling page. Is there any way to grab a list that includes the _index,md page? I’ve been using .CurrentSection.Pages which is great it returns all the pages but no _index page.

I can manually prepend it to my list as removing the _index means the section isn’t a real section and .CurrentSection.Pages stops working as I’d like. I can’t really have _index.md as a blank page as its needed to ensure it acts like a section so its a dilemma.

My interpretation of the documentation is that this isn’t possible but any ideas would be appreciated, thanks.

Example section

/section/_index.md
/section/activity.md
/section/response.md
/section/conculsion.md

Did you tried .Data.Pages ? It’s render the _index.md page also.

Thanks but .Data.Pages returns Pages(0) for me at my section level.

Interesting that in the scenario I have described the _index is actually the .Parent page and not a sibling page.

This is what I’m using and it is sufficient. I only include the partial if len .CurrentSection.Pages is greater than zero.

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

If Pages does not return the Section, it suggests that you’re on a very old Hugo version. That was the behaviour at some point (back then people used {{ $pages := .Pages | union .Sections }}.

OK, thank you I will investigate.

I’m using using hugo v0.87.0+extended darwin/amd64 BuildDate=unknown