List of content on homepage with resources (headless)

I’ve tried searching for solution extensively, but unfortunately I have failed to find an answer that would solve my issue.

Basically what I am trying to do is list some content on the homepage of the site along with its respective resources and I would like this content not to be listed anywhere else on the site, ie. no listing page.

Here is a visual ASCII mockup of what I am trying to achieve:

Section with listed content:
+---------+  +---------+
|  img    |  |  img    |
|---------|  |---------|
| Title   |  | Title   |
| Content |  | Content |
+---------+  +---------+

My content structure is as follows:

content
|-headless
  |-index.md / _index.md <-- I've tried both names
  |-first
  | |- index.md
  | |- logo
  |    |- img-first.png
  |-second
    |- index.md
    |- logo
       |- img-second.png

File content/headless/index.md(_index.md) has headless: true set in its front-matter.

Issues I am having are:

  1. If opt for Branch bundle (_index.md) I can easily list all its child content along with their respective resources, but even with headless option turned on the site still tries to list content when user navigates to http://localhost:1313/headless
  2. When I try and make it a Leaf bundle (index.md), then the headless option really works and the site does not try to list the nested content, but now I don’t know how to access each page’s resources. I used the following code to list the children:
    When using Leaf bundle:
{{ $headless := .Site.GetPage "/headless" }}
{{ $pages := $headless.Resources.ByType "page" }}
{{ range $pages}}
  ...
  don't know how to get page resources from here
{{ end }}

Is what I am trying to achieve even possible and if it is, how would one go about doing it?

One thing I would like to point out is that I don’t need the content under headless folder to be available in some listing page nor do I need it as a single page. I just need to call it/list it on the homepage in some arbitrary section.

Any help is greatly appreciated.

structure

content/
β”œβ”€β”€ things/
β”‚   β”œβ”€β”€ thing-1/
β”‚   β”‚   β”œβ”€β”€ feature.jpg
β”‚   β”‚   └── index.md
β”‚   β”œβ”€β”€ thing-2/
β”‚   β”‚   β”œβ”€β”€ feature.jpg
β”‚   β”‚   └── index.md
β”‚   └── _index.md
└── _index.md  <-- home page

content/things/_index.md

+++
title = 'Things'
date = 2022-04-09T11:13:53-07:00
draft = false
[cascade._build]
  list = 'local'
  publishResources = false
  render = 'never'
+++

layouts/_default/home.html

{{ range (site.GetPage "things").Pages }}
  {{ with .Resources.GetMatch "feature.jpg" }}
    {{ with .Resize "200x webp" }}
      <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
    {{ end }}
  {{ end }}
  <h2>{{ .Title }}</h2>
  {{ .Content }}
{{ end }}
3 Likes

This is incredible!
Thank you so very much for your help! This is exactly what I was looking for and there is no way on Earth I would manage to figure this one out by my self.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.