Using headless pages in section lists in hugo

I’ve got a requirement to build a section page that is comprised of some static header material, static footer material, and several sections of user-managed content. This user managed content is fragmentary, and as such should not have a permalink.

I thought that a good way to do this might be to use headless pages. If this is the wrong approach, stop here and tell me so.

It looks like to do that, these fragments must have a directory with an , and should be accessible using the .Site.GetPage operator.

I’m struggling with figuring out how to use .Site.GetPage to get a list of pages to iterate over. There will be 2…n user sections, and I don’t want to rebuild the section’s template if the number of content modules changes.

I’m assuming either there’s some magic to query multiple pages using .Site.GetPage , or there’s an entirely different operator for this.

That, or I’ve completely misunderstood how to use headless pages.

Here’s my template for the section ( ../layouts/the-range/section.html ):

{{ define "main" }}
    <div id="page-wrapper">
        <div class="halfhero" id="map"></div>

    {{ $sections := .Site.GetPage "/the-range/*" }}
    <!-- headless leaf content at .../content/the-range/*/ -->
    {{ range $sections }}
    <section class="range-section">
        <div class="section-content">
        <img src="{{.Site.BaseURL}}{{.Params.images}}">

    {{ end }}
{{ end }} 

The headless content is just a series of markdown files as leaf bundles.

Try this:

{{ $foo := .Site.GetPage "page" "foo" }}    
    {{ $foo := $foo.Resources.ByType "page" }}
    {{range $foo}}

What’s β€œpage” and β€œfoo” in this context? Is β€œpage” the same in GetPage and Resources.ByType?


Given a structure like this:

β”œβ”€β”€     # headless = true in front matter
β”œβ”€β”€ four
β”‚   └──
β”œβ”€β”€ one
β”‚   └──
β”œβ”€β”€ three
β”‚   └──
└── two

You can do:

{{ $headlessbundle := .Site.GetPage "/headless" }}
{{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
{{ end }}

Which should output:

1 Like

I think my GetPage construction is old (you may not need β€œpage”), but I think @pointyfar describes it well. β€œfoo” in my example is whatever section.

be careful with mulitlingual sites: this solution will only render if you have an index file for all languages (e. g. AND