Combine multiple sections

I’m having a problem with combining content from two sections on one page. For some reason, the exact same code does works just fine when used on the homepage, but it doesn’t work on any other pages. Your help is much appreciated! Thank you!

content

content / conf
--- _index.md
content / previous
--- 2017.md
--- 2016.md
content / current
--- 2018.md
+++
date = "2018-11-24T23:49:24+00:00"
layout = "page"
showdate = false
title = "Conferences"
+++

_layouts

_layouts/conf/list.html:

{{ define "main" -}}

<h6>Upcoming conferences</h6>
<div class="posts">
{{ range where .Data.Pages "Section" "current" -}}
<article class="post">
{{ .Title }}
{{ .Summary }}
</article>
{{- end }}
</div>

<h6>Previous conferences</h6>
<div class="posts">
{{ range first 10 (where .Data.Pages "Section" "previous") -}}
<article class="post">
{{ .Title }} 
{{ .Summary }}
</article>
{{- end }}
</div>

{{- end }}

For some reason, the exact same code works just fine on _layouts/conf/index.html but it doesn’t work on any custom layouts.

Hi,

That’s probably because .Data.Pages contains different pages when you are in the homepage vs when you are in the context of a sub-section.

Try if using .Site.Pages works the way you want.

I’m not sure what you mean here. In what way is it not working? In which custom layouts?

This page in the docs explains the difference between the various .Pages depending on context: Page variables | Hugo

1 Like

It worked! Thank you! All I had to do was replace .Data.Pages with .Site.RegularPages