Range in index.html to show subfolder content and directories

Hi, i’m trying to make simple theme in hugo. I want to show list of posts in the partial posts_list.html which is included in base_of.html

File structure:

content
 - folder_1
    - post_1.md
    - post_2.md
 - folder_2
    - post_3.md
    - post_4.md

baseof.html

<html>
    {{- partial "head.html" . -}}
    <body>
        {{- partial "posts_list.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
    </body>
</html>

in posts_list.html i’ve tried to use range:

{{ range .Pages }}
<p>{{ .Title }}</p>
{{ end }}

As a result i got this output on /index page
folder_1s (yes with s on the end out of nowhere)
folder_2s

and this on /folder_1:
post_1.md
post_2.md

  1. How to get rid of s? in the .Titles of directories?
  2. How to get this output on /index page:
    folder_1
    post_1.md
    post_2.md
    folder_2
    post_3.md
    post_4.md

config.toml

pluralizeListTitles = false

layouts/partials/posts_list.html

{{ range .Sections.ByTitle }}
  <p>{{ .Title }}</p>
  {{ range .RegularPages.ByTitle }}
    <p>{{ .Title }}</p>
  {{ end }}
{{ end }}

See:

1 Like

Thank you! it’s working great!

I’ve also added

.Site.Sections…

to make it work the same way on my website’s subpages.

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