Looping over resources

I’m hoping to be able to create a system where I can add a snippet (an “event”) in one place and have it show up on multiple pages. On top of that, I’d like to be able to define events in my root module and in each of my leaf modules (that import the base module) and have them all merged.

So, something like this layout:

./my-hugo/
  root/
    assets/
      events.yml
  leafA/
    assets/
      events-A.yml
  leafB/
    assets/
      events-B.yml

Then have a partial that uses transform.Unmarshal to load all the arrays of events in each yaml file into one slice, sort it, and then I can render a timeline page that has additional different events when building leafA and leafB.

At first I tried using resources.GetMatch "events*”, but I had failed to notice that it just retrieves the first match. I think I can do everything I want except find and range over all the different events files. Is there any way to do that that I might be missing?

with glob pattern ** to get every resource. At the bottom of that documentation page there’s a table of example glob patterns.

Ah! .Match returns a collection, .GetMatch doesn’t! :man_facepalming: Thanks - I should’ve caught that!

Why do I need **? Won’t resources.Match "events*" return all of the files in my example? I only need double stars if I want to search in subfolders, right?

Yes. That’s why I included the phrase “to get every resource”. You obviously don’t need to do that with your current structure.

1 Like

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