[SOLVED] Struggling to use .Resources in a leaf bundle

#1

In a template, I have this in a template file:

{{ (.Site.GetPage "page" "business").Resources.GetMatch "**" }}

I have tried other variants (The glob was just to see if anything is returned), but no matter what I try it returns <nil>. Now I believe I have successfully set up the leaf bundle, as {{ (.Site.GetPage "page" "business").Content }} successfully returns the content from business/index.md.

How do I get content from other pages in the leaf bundle though? The docs are really unclear.

#2

Can you share the full source code? In the meantime, have you also tried using Match instead of GetMatch?

What’s on the frontMatter of the page you are fetching ?

#3

Sharing here sorry because it’s pretty simple to recreate…

content/business/index.md

---
title:  "Testing?"
headless: true
---
Rawr! Boo.

content/business/about.md

---
title: "About This Company"
name: "about-alt"
date: "2018-06-15 00:00:00 +0800 AWST"
---
La monkey!

layouts/_default/baseof.html

<!DOCTYPE html>
<html>
        {{ (.Site.GetPage "page" "business").Resources.GetMatch "**" }}
</html>

Have tried using Match before. It just returns an empty array (i.e., [])

What am I missing? :frowning:

#4

Right now it looks like you are missing setting resources in the frontmatter.

---
resources:
 - src: images/someImage.jpg
 - name: 'image'
---
#5

In which file? content/business/index.md or about.md?

#6

content/business/index.md

#7

No difference sorry

#8

Then, if you can share the source code, we can try to help further

#9

I have… but if you think it’ll make a difference, I’ll go set up a minimal site demo

#10

Yes, it will help. Because we are all volunteers, and no one wants to copy and paste a bunch of files to recreate your issue. So please combine your templates and content into a Hugo project and share it. Then folks can assist you. Please refer to Requesting Help for guidelines on getting help in the forums. :slight_smile:

3 Likes
#11

Solved. Finally found a comment by bep himself, so I copied his example in at the top level. It worked so I investigated further.


Turns out I was just trying to use

.Site.GetPage "page" "section/headless-bundle"

when I should have just used

.Site.GetPage "page" "headless-bundle"


Follow up question: is it possible to get an array of headless bundles in a subdirectory to use as sections on a homepage without having to give them a common prefix? Currently I am using custom Params…

In the _index.md file for the homepage I have:

sections: [
    about,
    action,
    finance
]

And in the template file I currently have:

{{ range $.Params.sections }}
    <section id="{{ . }}">
      {{ $section := $.Site.GetPage "page" . }}
      <h1>{{ $section.Title }}</h1>
      {{ $section.Content }}
    </section>
{{ end }}

It works, but I don’t trust it to be reliable (users will probably forget to update the frontmatter for the homepage if they add or remove sections.