Confused how empty blocks work

This seems like a straightforward template rendering order problem but I can’t figure out the issue. I’ve got it working, but I can’t figure out WHY it works… I’m working on a new theme & my /layouts/_default/baseof.html template contains two blocks

{{ block "hero" . }}{{ end }}
{{ block "main" . }}{{ end }}

At this time, the hero block is defined in just one place: /layouts/blog/list.html. My intention is to use this hero block for the top portion of the current section’s index page.

What I’m observing:

  • When I have nothing in the hero block /layouts/_default/baseof.html template, the hero block defined in the blog post list template is rendered on the homepage on the site (defined with it’s own template, /layouts/home.html): ie: http://localhost:1313/
  • When I put anything other than whitespace in the default hero block in /layouts/_default/baseof.html (such as an empty HTML comment <!-- -->, it won’t add the hero from the blog list template.

Why is that? How could the block defined in the blog section show up on the homepage?

What Hugo version are you using?

I say this because I had a similar sense of confusion a few days ago. 0.74.0 broke the Hugo Docs site related to this. I added a fix an hour later in 0.74.1 that should get it back to 0.73.0 behaviour in this department, see


1 Like

I was using 0.74.0 earlier today, but I’ll upgrade to the latest and try to replicate it. Will follow up…

I’ve been so thrilled with Hugo for a few years, honestly surprised by a bug if that’s what it is. Assumed I did something wrong :slight_smile:

Looks like it was a regression in 0.74.0… upgrade to 0.72.2 and can’t replicate it anymore. Thanks!

1 Like

I still think it’s a bug in Go stdlib, which is why I reported it – because that bug in 74.0 caught me a pretty big surprise.

1 Like

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