Partials lookup order: custom section templates and section-specific partials

I have several questions, the first and most general being:
Where should section-specific partials go?

    1. Directly under each section?
layouts/
  people/
     footer.html
  events/
     footer.html
    1. Under each section, inside a partials folder?
layouts/
  people/
    partials/
      footer.html
  events/
    partials/
      footer.html
    1. Not under each section, but rather under sections in the partials folder?
layouts/
  partials/
    people/
      footer.html
    events/
      footer.html

From my testing, it seems to me that the only possible configuration is #3.
Furthermore, for this to work, it seems that a couple of conditions must be met.

  • Firstly, the partial must be called from the “parent” template like so:
    {{ partial "people/footer" . }}
    If we call the partial more generically like so:
    {{ partial "footer" . }}
    Then the general footer partial under layouts/_default/ would be rendered, and we wouldn’t get our customization.

  • Secondly, it seems that the parent template from which we call our footer partial (be that another partial, or in this case, a single.html file) must already be custom and specific to that section. In other words it must reside under the appropriate section in the layouts folder, and cannot be a generic template or partial under the _default/ or top-level partials/ folder.


As such the appropriate structure would have to look something like this:

layouts/
├── _default
│   ├── baseof.html         -->  {{ block "main" . }}{{ end }}
│   ├── home.html
│   ├── list.html
│   └── single.html         -->  {{ partial "footer" . }}
├── partials
│   ├── footer.html         -->  Footer content.
│   └── people
│       └── footer.html     -->  PEOPLE footer content.
└── people
    ├── list.html
    └── single.html         -->  {{ partial "people/footer" . }}


The point I want to bring up is:
Is it not possible for Hugo to take a generic template file, for example layouts/_default/single.html, and apply a section-specific partial like partials/people/footer.html if it finds one? and fallback to the default if none is to be found?

Does Hugo render a section-specific partial ONLY when calling that partial from an already section-specific layout file? i.e: layouts/people/single.html

Does that mean that if I want to have a different, say, footer, for each of my sections, I not only need to have my custom footer.html in each of my partials/section_name/ folders, but I also need to have custom and specific template files for each and every one of those sections even if those template files are identical, except for the “necessary” {{ partial "SECTION_NAME/footer" . }} section path calling:

layouts/
...
└── people
    ├── list.html
    └── single.html         -->  {{ partial "people/footer" . }}
└── events
    ├── list.html
    └── single.html         -->  {{ partial "events/footer" . }}
└── projects
    ├── list.html
    └── single.html         -->  {{ partial "projects/footer" . }}
...

I could, of course, place this logic in the parent template that does the calling: _default/single.html
(… and forgo Hugo’s internal Section matching to template files.)
Something like:

{{ if eq .Section "people" }}
         {{ partial "people/footer" . }}
{{ else if eq .Section "events" }}
         {{ partial "events/footer" . }}
{{ else if eq .Section "projects" }}
         {{ partial "projects/footer" . }}
{{ else }}
         {{ partial "footer" . }}

But it feels like this would defeat the purpose of Hugo already trying to detect sections and such automatically, and it becomes “manual” and repetitive.

Something marginally better would be to do:

{{ partial (printf "%s/footer" .Section) . }}

But it still doesn’t feel right when Hugo seems to have this functionality already under the hood.

To sum up: Am I missing something, or going about this the wrong way?
Ideally I would like to be able to have common templates under _default/ or partials/, and without any special calling to specific partials; but have Hugo automatically detect more-specific partials under the appropriate section folders.

I’d love some feedback. I have some dummy code in this repo here.

Partial templates must be placed in layouts/partials. They are agnostic with respect to content type, language, and output format.

If you want something like a partial that is not agnostic with respect to the features above, use content views with the Render method.