_index.md file rendering correctly... then overwritten by _default/single.html

Hi there,

I am fairly new to HUGO, so very much still learning.

Using version: hugo v0.134.1+extended

I have come across a problem with my _index.md file in the root of my content directory. When I run the ‘Hugo’ command - the page is rendered correctly, but later in the build process is overwritten by the template in layouts/_default/single.html.

I can verify that it is being rendered correctly when I run ‘Hugo --ignoreCache’ and watch the file preview in macOS. I can see it generate properly… then some seconds later it is replaced with the contents of the single.html file.

I have looked through the template lookup order and I thought I understood.
I have tried using ‘layout’ in the front matter. I have tried several different template names and locations… same result each time and I’m at a bit of a loss.

As this is my first post I am not able to post screenshots or more than a single link. I’ve included the filenames for the second and third screenshots. They are in the same folder as the first.

My content directory looks like:

And my layouts folder:

Current _index.md front matter
indexfrontmatter.jpg

From what I have read - the _index.md file should NEVER be rendered by a single.html template (it should look for list.html if it can’t find anything else above it)… but I must be making a mistake somewhere.

Can anyone help me narrow it down? Or help me somehow see the build process in a bit more detail to understand why this is happening?

Thank you for any help
Paul

To add:

All of my other pages render correctly with no issues.

If I delete the single.html template then it renders correctly - but Hugo gives me a warning (as expected) due to the missing single.html file

“WARN found no layout file for “html” for kind “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.”

You are more likely to receive a prompt and accurate response if you post a link to your project’s Git repository.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Ah, yes.

I was hoping there would be something simple without people needing to look at my disgraceful code and git commit messages (I’m learning git as part of this process). Lol

I’ve made the repository public here: GitHub - OutOfBreath/paulwood-photography: paulwood.photography hugo website

Delete the frontmatter line layout = "home" from content/_index.md and it works as it should.

See Template lookup order | Hugo

In the future, troubleshoot issues like this with the --printPathWarnings command line flag.

The root of the problem is this empty file: content/pages/contact-us/index.md. Because it’s empty, its slug value is an empty string. And you have this in your site configuration:

[permalinks.page]
pages = '/:slug/'

So when the contact-us page is published, it is written to public/index.html, clobbering the public/index.html file written by themes/squarepixel/layouts/home.html.html.

Recommendations:

  1. As @frjo mentioned, remove the layout front matter field from content/_index.md. It’s superfluous.

  2. Add front matter to content/pages/contact-us/index.md.

  3. Delete these files:

    • themes/squarepixel/layouts/_default/home.html
    • themes/squarepixel/layouts/_default/OLDHOME.html
  4. Optional, but I like this organization/naming better: move themes/squarepixel/layouts/home.html.html to themes/squarepixel/layouts/_default/home.html. The resulting layout structure:

themes/squarepixel/layouts/
├── _default/
│   ├── baseof.html
│   ├── home.html
│   ├── list.html
│   └── single.html
├── galleries/
│   ├── latestphotos.html.html
│   ├── list.html
│   └── single.html
├── pages/
│   └── about.html.html
├── partials/
│   ├── head/
│   │   ├── css.html
│   │   └── js.html
│   ├── footer.html
│   ├── head.html
│   ├── header.html
│   ├── menu.html
│   └── terms.html
└── photos/
    └── single.html
1 Like

Sadly this didn’t work for me.

I only added the front matter to try and force the template.

Thank you for the suggestion though

Thank you for the detailed reply! I would never have got that (except maybe by accident when I filled out the problem file.

Thank you also for the troubleshooting tip for the next time (I’m sure there will be a next time)

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