Methods for Nested Sections

Since methods like Section cannot be used for nested sections, what is the proper way to–

  1. Exclude a nested section e.g using eq or ne.
  2. Ranging over regular pages from a specific nested section, all excluding one.
.
└── test/
    ├── archetypes
    ├── content/
    │   ├── _index.md
    │   └── blog/
    │       ├── _index.md
    │       ├── countries/
    │       │   ├── _index.md
    │       │   ├── usa/
    │       │   │   ├── index.md
    │       │   │   └── cover.jpg
    │       │   └── cameroon/
    │       │       ├── index.md
    │       │       └── cover.jpg
    │       └── continents/
    │           └── _index.md/
    │               ├── africa/
    │               │   ├── index.md
    │               │   └── cover.jpg
    │               └── asia/
    │                   ├── index.md
    │                   └── cover.jpg
    ├── layouts
    └── hugo.toml

For example, are you asking “How do I range over regular pages in the blog section while excluding the blog/continents section?”

And, if that is your question, on which page do you wish the results to appear?

Yes, for question 1. I have a few places, but the homepage and related posts partial for now.

Question 2 is mostly about excluding some templates from certain nested sections, since we cannot do {{ if ne .Section "continents" }} for example.

You can compare with .Page.Path or .CurrentSection.Path or .CurrentSection.Title, etc.

Also, based on some recent rudimentary performance testing, I suspect that using a where statement will be faster than the complement function as described here. But I could be wrong.

I wanted to go with that solution for question one. If you don’t mind, could you please share a reproducible example I can study with both scenarios?

git clone --single-branch -b hugo-forum-topic-54775 https://github.com/jmooring/hugo-testing hugo-forum-topic-54775
cd hugo-forum-topic-54775
hugo server

Thanks. In my project, Method A worked and the rest returned nil.

Since the example site works fine, I can only conclude that your project is very different.

I will look into it and get back. I am on latest Hugo version. So, I will try and strip it down and see.