Odd build issues (theme layout not looking up correct template)

I have a very simple site I’m creating, at least it is right now.

Project structure



title: "My Site - Home"
date: 2022-12-06T10:33:25-06:00
draft: false
type: "hero"
hero_title: "Welcome to my page"
hero_image: "/images/player.png"


{{ define "main" }}
<div class="hero-container">
	<h1 class="hero-title">{{ .Params.hero_title }}</h1>
	<img class="hero-image" src="{{ .Params.hero_image }}" />
{{ end }}

The weird part about it is it will build and build correctly once. Just changing something in the single.html, or in the index.md causes the page to stop building. The hero/baseof.html is not used as the baseof, the hero image is not shown, the hero title disappears, etc…

The really weird thing is that it happens when a non-impactful change is made (e.g., literally adding a space at the end of the <img /> elment, then removing the space then saving will cause the build to go haywire.

hugo --printPathWarnings 
mv content/index.md content/_index.md
hugo --printPathWarnings 

Ok, I think I understand the what that you’re getting at - but I’m still confused about the why?

Switching the md to _index.md it never uses the ‘correct’ template for the hero page…

Edit: Ok I found this documentation that explains the _index.md file: Hugo - Using _index.md

But I still can’t figure out why it’s using the _default/single.html instead of the hero/single.html

The home page’s .Kind is home. It is neither a regular page (single) nor a section (list), but it behaves like a section (list) in that it receives a page collection in context.

Have a look at the template lookup order for the home page:

The underlying content file for section pages is _index.md. The same is true for the home page.

It is looking for layouts/hero/list.html.

1 Like

Awesome, thank you for the explanation and your time!

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