Single/list template doesn't use baseof

I’m starting out with hugo and just getting the hang of things.

I set up the following templates:

hugo/themes/mytheme/
`- layouts/
  `- _default/
     `- baseof.html
        list.html
        single.html
   - index.html

When generating my site, only the index.html is using my _default/baseof.html template. The _default/list.html and _default/single.html just produce empty pages, as if they don’t recognize the _default/baseof.html template at all.

My _default/baseof.html contains

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

And _default/single.html overwrites this

Hello world from single.html
{{ printf "%#v" . }}
{{ define "main" }}
	{{ .Content }}
{{ end }}

The output of a single page is:

Hello world from single.html &hugolib.PageOutput{
Page:(*hugolib.Page)(0xc0424ee500), 
paginator:(*hugolib.Pager)(nil), 
paginatorInit:sync.Once{
m:sync.Mutex{state:0, sema:0x0}, done:0x0}, 
resources:resource.Resources(nil), 
resourcesInit:sync.Once{m:sync.Mutex{state:0, sema:0x0}, done:0x1}, 
targetPathDescriptor:hugolib.targetPathDescriptor{
PathSpec:(*helpers.PathSpec)(0xc0426cf830), 
Type:output.Format{Name:"HTML", 
MediaType:media.Type{MainType:"text", SubType:"html", OldSuffix:"", Delimiter:".", 
Suffixes:[]string{"html"}, fileSuffix:""}, 
Path:"", BaseName:"index", Rel:"canonical", Protocol:"", IsPlainText:false, IsHTML:true, 
NoUgly:false, NotAlternative:false}, Kind:"page", Sections:[]string{"userdocs"}, 
BaseName:"welcome", Dir:"userdocs/", LangPrefix:"en", IsMultihost:false, URL:"", 
Addends:"", ExpandedPermalink:"", UglyURLs:false}, outputFormat:output.Format{
Name:"HTML", MediaType:media.Type{MainType:"text", SubType:"html", 
OldSuffix:"", Delimiter:".", Suffixes:[]string{"html"}, fileSuffix:""}, Path:"", 
BaseName:"index", Rel:"canonical", Protocol:"", IsPlainText:false, IsHTML:true, 
NoUgly:false, NotAlternative:false}} 

What am I missing here?

It’s difficult to say for sure without seeing all the code. It might help you to read the docs here: https://gohugo.io/templates/base/#override-the-base-template especially this note:

Code that you put outside the block definitions can break your layout. This even includes HTML comments. For example: …

1 Like

Extend the file …
I use the comment to see what happens.

<!DOCTYPE html>
{{ "<!-- layout/_default/baseof.html -->" | safeHTML }}
<html>
{{ block "main" . }}{{ end }}
</html>

try the single with

{{ define "main" }}
{{ "<!-- layouts/_default/single.html -->" | safeHTML }}
{{ .Content }}
{{ end }}

I think that last comment about the outside of block content was the issue indeed. When I removed the “outside” content, it started to work.

Is there no error message for this? Or did I miss it?

I’m not sure, but I don’t think so? Other than that note in the docs.