Section not set properly

Hello there,

I try to build a page that should use the concept of ‘sections’ heavily. But obviously I have not yet got the concept right.

Given have file structure such as:

/content/
/content/_index.md
/content/concerts/01/_index.md
/content/concerts/01/concert1.md
/content/concerts/01/concert2.md
/content/concerts/02/_index.md
/content/concerts/02/concert3.md
/content/concerts/02/concert4.md

Each concertX.md file looks like this:

---
title: concert[X]
---

index.md files are empty for now.

the theme consists of only two files:
themes/test/layouts/_default/baseof.html:

<!DOCTYPE html>
    <html lang="en">
        <head>
        <meta charset="UTF-8">
    </head>
    <body>
        {{ block "content" . }}{{ end }}
    </body>
</html>

single.html:

{{ define "content" }}
{{ range .Site.Pages }}
    {{ .Section }} - {{ .Name }}<br>
{{end}}
{{ end }}

The expection of the output at localhost/concerts/concert1.html would be:

concerts - 
concerts - 
categories - Categories
concerts - Concerts
tags - Tags
01 - concert1
01 - concert2
02 - concert3
02 - concert4

But instead I have:

concerts - 
concerts - 
categories - Categories
concerts - Concerts
tags - Tags
concerts - concert1
concerts - concert2
concerts - concert3
concerts - concert4

Why do the concert[X] pages not get their parent folder name as Section? According to the documentation I would assume that the file /content/concerts/02/_index.md ensures for example that 02 is a section which would include concert3 and concert4…

hugo version
Hugo Static Site Generator v0.50/extended linux/amd64 BuildDate: unknown

Hi there – instead of .Section, perhaps what you want is .CurrentSection.

The reason you are getting that output is because of the below, which is quoted from the docs you linked :wink:

When we talk about a section in correlation with template selection, it is currently always the root section only ( /blog/funny-cats/mypost/ => blog ).

If you need a specific template for a sub-section, you need to adjust either the type or layout in front matter.

Ok, I earned that “rtfm” hint… :wink: Thanks for pointing out! I implemented the feature I needed via .CurrentSection

Does anybody know the reason “root level sections” and “nested sections” are not treated the save by .Section. The way the implementation works feels a bit hacky to use really.