I want to render all the markdown files inside every folder except the static one in my home page of the website, one way of doing that is by using union in hugo, but as number of folders increase, I see myself repeating unions all over the place (code with union is commented, which is working by the way), so I thought using a slice would be a better idea, but when I try to use slice, I get the following error -
failed to render pages: render of "home" failed: "(Directory Path)\layouts\index.html:12:19": execute of template failed at <.Pages>: can’t evaluate field Pages in type string
directory structure
code for index.html
{{ define "main" }}
<ul class="homepage-topic-sections-container">
{{$sectionNames := slice "posts" "problems" "tutorials"}}
{{range $index, $sectionName := $sectionNames}}
{{ range where .Pages "Section" $sectionName }}
{{/*
{{ range union (union
(where .Pages "Section" "posts")
(where .Pages "Section" "problems"))
(where .Pages "Section" "tutorials")
}}
*/}}
<li>
<section class="homepage-topic-section">
<h1 class="topic-heading"><a href="{{.Permalink}}">{{.Title}} </a></h1>
<div>
{{ range .Pages }}
<h3><a href="{{.Permalink}}">{{.Title}} · {{.Date.Format "January 2, 2006"}}</a></h3>
{{ end }}
</div>
</section>
</li>
{{end}}
{{end}}
</ul>
{{ end }}

https://gohugo.io/templates/introduction/#the-dot:
In the code below, the dot in
.Pageshas the value of the current item in the firstrangeaction. The type of that value is string, and it does not have the fieldPages. That's why it failed withexecute of template failed at <.Pages>: can’t evaluate field Pages in type string.One possible fix is to use
$.to access the global context:.Pages==>$.Pages.Maybe a better solution is to list the exclude sections instead. Then you don't need to modify the code when more folders are added: