Baseof.html doesn't generate any content


#1

I’ve created the most simple Hugo project, without any content, the only thing I’ve done is creating a personal theme from scratch, just to get my hands dirty, with hugo new theme xxx. I wanted to understand how base templates works, so I created also a baseof.html file in the themes/xxx/layouts/_default folder. I also have, obviously, the index.html for the homepage template, created directly by Hugo. I understood that what I write in the base template file, will be shared by all pages, also the homepage, instead if I launch hugo server -w -D, the tab opened in the browser shows a completely white (empty) page. I guessed it would show any text I write in the body of base template, instead it shows nothing, why? Isn’t base code shared (and so, showed) by all pages?


#2

Yes, but you need something in your index.html file as well. And for it to use the base template, you need to define at least one of the blocks in it. This should be in the documentation.


#3

Thanks for your answer! Is this valid only for the homepage, right? Because, according to the video in the documentation (https://gohugo.io/templates/base/), writing a simple string should populate all single and list templates but, as you told me, this is not valid for the homepage, did I get it? Also the documentation seems not to tell that I need to put some content on the index.html, or that I have to define at least one block.


#4

No, the base template works for all regular templates (not partials). So if you have one in _default/baseof.html (and that is your only base template), that base template will be applied to all other templates that defines at least one of the blocks. The last part is important.

This is what I mean by “define”:

You will find the “main” block in the baseof.html template.


#5

Now I’ve finally understood! Thank you! My mistake was that of not considering the {{ block ... }} thing. Thanks again!