Regular pages from a section in a nested list

Trying to list the top-level sections and their pages:

<ul>
	{{ range .Site.Sections }}
	  	<li>
		    <a href="{{ .RelPermalink }}">{{ .Name }}</a>
			<ul>
				{{ range where .Site.RegularPages "Section" .Name }}
					<li>
						<a href="{{ .Permalink }}">{{ .Title }}</a>
					</li>
				{{ end }}
			</ul>
	    </li>
	 {{ end }}
</ul>

Content structure:

content/

    - section1/
        - page1/
            index.md
        - page2/
            index.md
        _index.md

    - section2/
        - page1/
            index.md
        - page2/
            index.md
        _index.md

… And I only get the two section names, without the pages under them.

Try this:

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

Doesn’t work :frowning:

I think this was one of the first things I tried.

This works for me. Perhaps your pages have draft set to true ?

1 Like

My goodness… How did you know? :no_mouth:

2 Likes

Happens to me all the time :stuck_out_tongue:

Ahem, Your content isn't showing because it is a draft. Pass it on! :slight_smile: