Reputation: 45
For this Hugo site, I have two sections in my "content" folder, "posts" and "projects", each with their own pages. The site.com/projects/
and site.com/posts/
pages display their relevant content correctly. On my home page, I'd like to display some entries of both sections. Here is layouts/index.html
:
{{ define "main" }}
<div class="homepage-content">
{{ .Content }}
</div>
<h1>Blog Posts:</h1>
<div class="articles">
{{ $post_pages := where (where site.Pages "Type" "in" "posts") "Params.hidden" "!=" true }}
{{ range (.Paginate $post_pages).Pages }}
{{ partial "post-summary.html" . }}
{{ end }}
</div>
<h1>Projects:</h1>
<div class="articles">
{{ $project_pages := where (where site.Pages "Type" "in" "projects") "Params.hidden" "!=" true }}
{{ range (.Paginate $project_pages).Pages }}
{{ partial "post-summary.html" . }}
{{ end }}
</div>
{{ partial "pagination.html" . }}
{{ end }}
What happens is, that both code blocks end up rendering a list of the pages from the "posts" section, and if I reverse the order (placing the code block for the "projects" section first) they both display pages from the "projects" section. What seems to be happening is that there's some kind of hidden variable that isn't being reset between the code blocks. After going through the Hugo docs for about an hour, I couldn't for the life of me find the reason. I've already specified both sections under "mainSections" in the params file if that makes any difference (although I don't imagine it does)
For reference, I'm using the anubis theme as a base (although it's been somewhat heavily modified) but again, I don't think it's related.
Upvotes: 0
Views: 504
Reputation: 45
A kind member of the Hugo forum has answered my question: https://discourse.gohugo.io/t/list-is-displaying-content-from-the-wrong-section/41255
I made two mistakes. I paginated twice, which doesn't work. I also used .Pages
instead of .RegularPages
, which isn't recommended (see here).
User jmooring
provided the following two options for how I could do what I was attempting:
Upvotes: 2