How to enumerate subfolders

I’m having a little bit of hugo-writer’s block at the moment. I know the answer to this is simple but I can’t remember how to do it.

Say I have a layout for a bunch of events as follows:

etc. etc.

How can I enumerate the immediate direct sub-folders of content/events/foo/, so that on the parent content/events/foo/ I can have a list of links to event-specific related information.

I know this is done at theme template level, but I just can’t think how at the moment !

Hope this makes sense ?

Your are describing this content structure:

└── events/
    └── foo/
        ├── programme/
        │   └──
        ├── registration/
        │   └──

In the above, “foo” is a leaf bundle, meaning it can have no descendants. See FAQs:

I see, so I’d have to change the parent foo/ to foo/ ? And then it would be possible to enumerate immediate descendants ?

Yes, that is correct.

Ok, and in terms of actual implementation, would I be looking at:

range .Pages or something else ?

Yes, that’s correct. You should experiment a bit; it’s a great way to learn.

You’ll probably want a list template unique for the “events” content type. Create layouts/events/list.html.

I think the thing that was/is confusing me is the whole “branch bundle is a list” thing, because I’m using the branch bundle as a category rather than, e.g. list of blog entries. So thinking of it as a list is a bit odd mentally.

However, I guess as you say, using a list template you can ultimately make it look like a single page anyway.

You can list content on any page kind: home, section, page, taxonomy, or term. It’s just a matter of where you place the content to be listed.

And the content to be listed doesn’t have to have its own URL; each item can be a snippet from another content file.

Slight problem, having changed to, a previous layout on a higher level page is now broken as it was using where .Site.RegularPages "Type" "events" as a test and obviously cannot display foo any more as foo is no longer a regular page.

Is there a way to fix this ?

Yes, there is a way to fix this. But without seeing your project repository, I have no idea which is the correct way to do it.

Bit tricky to share a repo as it contains all sort of stuff I’d have to spend an eternity stripping out, however here is a bigger snippet that should hopefully make it clearer ?

This is located on the homepage, and so current/upcoming events are displayed (eventShowUpcoming set in the of the events subfolder) but other stuff is not.

<ul class="grid mt-l-xl card-text-colour" role="list" data-rows="masonry" data-layout="50-50">
{{ range (where (where .Site.RegularPages "Type" "events") ".Params.eventShowUpcoming" "eq" "true" ).ByDate.Reverse }}
      <li class="card flow">
      <h3><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h3>
      {{ $sDate := .Params.startDate }}
      {{ $sDate = time.AsTime .Params.startDate }}
      {{ $sDate = $sDate.Format "2 January 2006" }}
      {{ $eDate := .Date }}
      {{ $eDate = time.AsTime .Params.endDate }}
      {{ $eDate = $eDate.Format "2 January 2006" }}
      <p class="smallfont"><i>{{ $sDate }}&nbsp;&ndash;&nbsp;{{ $eDate}},&nbsp;{{.Params.eventLocationHeader}},{{.Params.eventCountryFull}}</i></p>
      <p>{{ .Params.homepageSummary }}</p>
      <p><a href="{{ .RelPermalink }}">Find out more&hellip;</a></p>
{{ end }}

I wanted to see the repo to see the content structure, not the template.

Is the content under event consistent, or is it a mix of section pages and regular pages?

For example, this is consistent:

├── events/
│   ├── bar/
│   │   ├── something/
│   │   │   └──
│   │   ├── something-else/
│   │   │   └──
│   │   └──
│   └── foo/
│       ├── programme/
│       │   └──
│       ├── registration/
│       │   └──
│       └──

And this is not

├── events/
│   ├── foo/
│   │   ├── programme/
│   │   │   └──
│   │   ├── registration/
│   │   │   └──
│   │   └──
│   └──

Ah, sorry for the misunderstanding.

At the moment what is under events is a purely academic question, because the site is very much under design, so it can contain (or not contain) whatever you think it should ! :wink:

But at the moment, my “right now” layout is:

├── events/
│ ├── foo/
│ ├── programme/
│ │ └──
│ ├── registration/
│ │ └──
│ │──


So the idea is that every event would have a seperate sub-folder under events/ , so events/foo2024/ or whatever.

Edit to add: I’d say this concept matches your “consistent” example ?

Since every event is a section (has an file, do this:

{{ range (site.GetPage "/events").Sections }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

That doesn’t seem to return anything (http://localhost:1313/events shows them, so they are there)

Works great for me:

git clone --single-branch -b hugo-forum-topic-48288 hugo-forum-topic-48288
cd hugo-forum-topic-48288
hugo server

Not to put too sharp an edge on this, but I cannot spend any more time without access to your repository. Guessing is not a wise usage of my time or yours.