title: How to List All Pages of a Section in Hugo
body: <p>I'm trying to list pages from a section on the front pages. This shouldn't be too hard; for example, with the following hierarchy (names genericised):</p>
  <pre><code>/content/
          |_ test-page.md
          |_ /section-name/
                          |_ page1.md
                          |_ page2.md
  </code></pre>
  <p>Using the following loop:</p>
  <pre><code>{{ range .Pages }}
     ...
  {{ end }}
  </code></pre>
  <p>Gives the list page for <code>/section-name/</code> as <code>&quot;section-names&quot;</code>.</p>
  <p>OK, well, I looked online for other solutions. For example:</p>
  <pre><code>{{ range first 5 (where .Data.Pages &quot;Section&quot; &quot;in&quot; (slice &quot;section-name&quot;)) }}
  </code></pre>
  <p>But this still returns <code>&quot;section-names&quot;</code>.</p>
  <p>OK, so the <a href="https://gohugo.io/templates/lists/" rel="nofollow noreferrer">documentation</a> has example of where clauses and grouping. For example, <code>{{ range (.Pages.GroupBy &quot;Section&quot;).Reverse }}</code>. Let's try a similar concept:</p>
  <pre><code>{{ range (.Pages.GroupBy &quot;Section&quot;) }}
     {{ .Key }}
  
     {{ range .Pages }}
  
        {{ .Title }}
  
     {{ end }}
  {{ end }}
  </code></pre>
  <p>This seems like it would print every key, then print every page under that key. However, it prints <code>section-name Section-names</code> instead of what I was hoping for, <code>section-name page1 page2</code>.</p>
  <p>What?</p>
  <p>Also, using a simple loop like <code>{{ range .Pages }}</code>, why does <code>test</code> not appear as soon as a section folder is created? I don't understand Hugo's seeming obstination to show me just the section page.</p>