HUGO

Find First Page Bundle in a Section

I am building a site that is using branch page bundles to group content together that will be displayed on a front-page style layout. It is for a course I am teaching. Content is grouped by week. When a user lands on the home page, I want to retrieve the content necessary to populate the front page layout from the week’s content bundle. I can’t figure out how to ask Hugo for the most recent page bundle in the section. Once I have a path to that index page, I can build the rest of the layout easily because the index file (_index.md) in the bundle contains front matter that populates the layout.

Thanks @jmooring. That is my current solution.

{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections  }}
{{ range first 1 $pages }}	


{{ end }}

But it will give me any of the pages and I want to isolate the index page for each bundle. My directory looks like this:

content/
|-- about
|-- sessions
| |-- week-02
| | |-- _index.md
| | |-- introduction.md
| | |-- lesson-02.md
| | |-- …
| |-- week-01
| | |-- _index.md
| | |-- lesson-01.md
| | |-- …

I would like to locate the most recent page bundle in the sessions folder, and access its associated index page. Right now, where and first deliver the most recent page, regardless of whether or not they are an index page.

layouts/_default/index.html

{{ define "main" }}
  {{ .Content }}
  {{- with .Site.GetPage "/sessions" -}}
    {{- range first 1 .Sections -}}

      <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
      <p>{{ .Summary }}</p>
      {{ if .Truncated }}
        <p><a href="{{ .RelPermalink }}">Continue reading...</a></p>
      {{ end }}

      <h3>Foo</h3>
      <p>{{ .Params.foo }}</p>

      <h3>Bar</h3>
      <p>{{ .Params.bar }}</p>

      <h3>Baz</h3>
      <p>{{ .Params.baz }}</p>

    {{- end -}}
  {{- end -}}
{{ end }}

Try it:

git clone --single-branch -b hugo-forum-topic-26567 https://github.com/jmooring/hugo-testing hugo-forum-topic-26567
cd hugo-forum-topic-26567
hugo server

@jmooring That worked well. Many thanks!