Is it possible to have more than one baseof template?

Hi all,

I had a hard time this afternoon trying to wrap my had around the concept of base templates. My goal was to have one layouts/_default/baseof.html for the whole site and a more specific one layouts/sections/baseof.html for all section pages.

To make it short: I didn’t get it working. Hugo defaults back to _default/baseof.html ignoring the one under sections.

So, could someone help me and please clarify if it is possible to have more than one baseof.html as lined out in the docs or am I wrong in my understanding of the docs and only one base template is possible?

Thanks for your replies.

Hi

I coincidentally got the exact same issue today. Although I’ve the second baseof.html file located next to single.html for a specific type for different views instead of layouts/sections/. But indeed, Hugo defaults back to _default/baseof.html

The thing is… If I remove the default one, the one in the section is still not rendered.

I think we are misunderstanding the lookup order / locations.

Regards,

Bas

The base template documentation is here https://gohugo.io/templates/blocks#base-template-lookup

And it is possible to have several, but my tip is to focus on the “current-path” in the doc. So if it picks up the list template in _default, then the “current-path” will be _default.

Thanks @bep

@totoff It is working for me now. I was apperently running an older version of Hugo (v0.21 is blocked by my virus scanner). So make sure you are running at least v0.20.7

And like @bep mentioned: place your second baseof.html in the same folder as the files that use it. So either layouts/section/ if you use it for the list view, or in layouts/[type]/ if you use it for rendering different views.

Regards,

Bas

hi,

thanks @bep and @bschoen. glad you got it working @bschoen. i’m lacking the time to investigate this again today but i’ll give it another try next week.

for the moment i can say that i already tried (with v0.21) the following which didn’t work:

_default
/baseof.html
/list.html

section
/baseof.html
/mysection.html

however, without further reading in the docs i understand from you posts that

section
/baseof.html
/list.html
/mysection.html

would be the route to go?

i’ll try next week and report back. thanks again.