# List RegularPages In Same Folder in Single Template

**URL:** <https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375>\
**Category:** support\
**Created:** [November 11, 2024, 3:27am UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375 "2024-11-11T03:27:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Holland](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_holland/32/20250_2.png) [@Michael\_Holland](https://discourse.gohugo.io/u/Michael_Holland)\
**Post date:** [November 11, 2024, 3:27am UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/1 "2024-11-11T03:27:24Z")

</div>

I’ve been using Hugo for a few years, building several sites already. I’m currently rebuilding an old site in Hugo witch has a deep folder structure. As part of the template, I want to have a nav block that lists the other regular pages **in the same folder** in the single template. It seems like this should be possible but I haven’t figured out the code from the docs and I’m not finding any examples. I think the following code should be close but doesn’t produce any links:

```auto
       {{ with .File }}
          {{ $pages := where site.RegularPages "Dir" .Dir }}
          {{ range $pages }}
            <p><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></p>
          {{ end }}
        {{ end }}

```

Any ideas?

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [November 11, 2024, 7:22am UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/2 "2024-11-11T07:22:34Z")

</div>

I would use the page tree instead

##### single.html

```auto
   {{ range .Parent.RegularPages }}
      {{ if ne $ . }}<!-- skip current page -->
         <p><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></p>
      {{ end }}
   {{ end }}

```

---

<div class="post-metadata">

**Author:** ![frjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/frjo/32/18626_2.png) [@frjo](https://discourse.gohugo.io/u/frjo)\
**Post date:** [November 11, 2024, 7:35am UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/3 "2024-11-11T07:35:46Z")

</div>

I think this should work

```auto
{{ with .File }}
  {{ $section := site.GetPage .Dir }}
  {{ range $section.RegularPages }}
      <p><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></p>
  {{ end }}
{{ end }}

```

@irkode example works perfectly when dealing with Hugo sections.

But only the first level of directories inside the `content` directory are proper Hugo sections. All the sub directories are just that, from Hugos point of view.

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [November 11, 2024, 8:21am UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/4 "2024-11-11T08:21:52Z")

</div>

> [@frjo](#):
>
> But only the first level of directories inside the `content` directory are proper Hugo sections. All the sub directories are just that, from Hugos point of view.

The sub dirs are also sections according to [Parent | Hugo](https://gohugo.io/methods/page/parent/)

> A _section_ is a top-level content directory, or any content directory with an \_index.md file.

And it works for

```auto
/content/section/folder/file1.md
content/section/folder/file2.md

```

Being on page `file1` my code will return a link to `file2`

If section pages are not needed we might use build options to skip rendering them (would have to test that)

---

<div class="post-metadata">

**Author:** ![frjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/frjo/32/18626_2.png) [@frjo](https://discourse.gohugo.io/u/frjo)\
**Post date:** [November 11, 2024, 11:47am UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/5 "2024-11-11T11:47:16Z")

</div>

> [@irkode](#):
>
> or any content directory with an \_index.md file

Absolutely right, missed that part.

So my answer is only relevant when one does not have a `_index.md` file in the sub sections.

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [November 11, 2024, 1:19pm UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/6 "2024-11-11T13:19:50Z")

</div>

@frio absolutely right.

the .File version would need an index.md cause we need a File.  
If there’s none (if that is possible) using Page.Path | path.Dir to get the parent page may be an option… just thought out loud

the .Parent will need at least an empty `--- ---` \_index.md in each folder

* * *

you may even suppress the rendering of the list pages using build options but than ofc you will have to generate links _to_ the pages somewhere else 😉

```auto
[[cascade]]
  [cascade._target]
   kind = 'section'
   path = '/folder**'
  [cascade.build]
    render = 'never'
[[cascade]]
  [cascade._target]
   kind = 'page'
   path = '/folder**'
  [cascade.build]
    render = 'always'

```

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [November 13, 2024, 1:20pm UTC](https://discourse.gohugo.io/t/list-regularpages-in-same-folder-in-single-template/52375/7 "2024-11-13T13:20:27Z")

</div>

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