User2
March 28, 2021, 9:06pm
1
I would like to know how I could list all pages in a sub-folder using Hugo. This is how my content folder is structured:
content\
--- general\
------ file1.md
------ file2.md
------ file3.md
And now I would like to access file1, file2 and file3 in the main list.html file which is located under layouts/_default . I tried using things like:
{{range where .Site.Pages "File.Dir" "general"}}
and
{{range where .Site.Pages "Section" "general"}}
as well as both combinations using general/
. I also tried a few other solutions from similar topics, but surprisingly, none of them worked at all.
However neither of them seems to work.
User2
March 29, 2021, 8:11am
3
Thank you very much for your answer. This seems to work fine. I suppose I forgot to use this combination, because I tried something with .Site.RegularPages before, but I wasn’t sure how exactly this worked.
If anyone is interested in the exact answer…
I had to use the second example with .Site.RegularPages and “Section”:
{{range where .Site.RegularPages "Section" "general"}}
bep
March 29, 2021, 9:08am
4
What I would recommend is you do something ala:
{{ $general := site.GetPage "general" }}
{{ range $general.RegularPages }}
{{ end }}
2 Likes
User2
March 29, 2021, 9:16am
5
Thank you for the recommendation. This looks quite clean and intuitive to use. I’ll consider this suggestion with great pleasure.
1 Like
bep
March 29, 2021, 10:56am
6
A related tip:
{{ $general := site.GetPage "general" }}
{{ range $general.RegularPagesRecursive }}
{{ end }}
The above will recurse into any subsections.
Also, note that I had a typo in my first example (corrected now).
1 Like
system
Closed
March 31, 2021, 10:57am
7
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.