Iterating over sub-directories inside a directory

Consider the following directory structure in the root directory of a hugo static site:

content
|
└── A
    └──A1
       ├── a.md
       └── b.md
    └──A2
       ├── a.md
       └── b.md
    └──A3
       ├── a.md
       └── b.md
             .
             .
             .      

All I want to do is render the ‘Content’ of the markdown files; but I want to do this directory-wise i.e., I want a separate row for all the sub-directories viz. A1, A2,… and inside each row, I want the content of the .md files inside the directory corresponding to that row. So it should look like:

/Row 1/ a.md b.md //these are files in A1
/Row 2/ a.md b.md //these are files in A2
/Row 3/ a.md b.md //these are files in A3
.
.
My efforts:
I tried iterating over folders with the loop {{ range where .Pages “Type” “A”}} and then an inner loop using ‘.’ to refer to the sub-directories; but the outer loop straight away goes to the markdowns without storing a reference to the subdirectories in the dot(.) Since everything is a page, why does this not work? More importantly how to get this done? I have tried rewriting loops and reading the hugo docs. I am new to Hugo and have no Go programming background. I know this is definitely an easy issue but it’s really annoying because I can’t seem to find the right way. Any help is appreciated. Thanks!

In the official documentation there is nothing about selective rendering of Nested Sections in list pages, as far as I know.

However it is possible to do the above as needed by performing a simple .Permalink (or .RelPermalink ) check like so:

        {{ if in .Permalink "A1" }}
              {{- range .Pages -}}
              <--- whatever --->
              {{- end -}}
        {{- end -}}

This is what I use typically in the template under /layouts/_default/list/.

It is the simplest way that I know. Others may also offer their own workarounds.

But how do I loop over the subdirectories, since with this workaround as well, I need
{{ if in .Permalink "A*" }} for all the directories.
I want an outer loop which iterates over the directories and then an inner loop which iterates over the files (inside the folder that the outer loop points to at that moment).

No.
In the same template as above i.e. /layouts/_default/list/ you need to have the following conditions to achieve this:

{{- if .Sections -}} or {{- if .FirstSection -}}
            {{- range .Sections -}}
<-- controls the layout of First Section list pages over the Nested Sections--->
{{- end -}}
{{- end -}}

{{- range .Pages -}}
<-- controls the layout of Nested Sections list pages --->
{{- end -}}

I thought that you were after individual Nested Sections hence my previous reply.