Hidden/headless section using content adapters

To create hidden (or headless) pages (i.e. pages that cannot be accessed on their own, but whose content can be included on other pages), you can use Build Options.

The documentation explains how to do this using front matter in markdown files, but what if your pages are being generated using Content Adapters?

Let’s say you have customer testimonials you’d like to include in other pages, but you don’t want individual testimonials to have their own page. In your content/testimonials/_content.gotmpl file, add a dictionary for the build options:

{{ $build := dict
  "list" "local"
  "publishResources" false
  "render" "never"
}}

Then add this to your page like so:

{{ $page := dict
  "kind" "page"
  "title" $testimonial.name
  "dates" (dict "date" (time $testimonial.date))
  "params" $params
  "path" $testimonial.id
  "build" $build
}}
{{ $.AddPage $page }}

You’ll notice that you now have a blank /testimonials page. To hide it as well, create a new file content/testimonials/_index.md and add the following:

+++
title = 'Testimonials'
[build]
  list = 'never'
  publishResources = false
  render = 'never'
+++

Now your /testimonials page will be hidden too.

To include your testimonials in other pages, use the following:

{{ $testimonials := site.GetPage "/testimonials" }}
{{ range $testimonials.RegularPages }}
  {{ print .Title }}
  {{ print .Date }}
  ...
{{ end }}
2 Likes