I’m super new to Hugo and I’m trying to turn a sketch I did using pure html / css to create a Hugo theme.
I’ve hit a roadblock. I don’t understand how do you correctly use baseof.html file. Every theme I look at has it. I decided to create one myself - as I thought it would be a “base” for every generated html. But it does not seem to be applied at all.
Removing it changes nothing - as it seems that only list.html and single.html are used.
What’s the correct structure and a way to use it?
A good example would be to create Hugo site with the command line, then create new theme, and then check how the theme’s baseof.html file is structured. At least that’s how I learnt to use it.
While you can override the base template and other blocks within it, basically, it includes the code which all your templates (might) share while the {{ block "main" . }}{{ end }} part is where content begins to differ between templates.
Using the example above of baseof.html.
Summary
<html>
<head>
<meta charset="utf-8">
<title>{{ block "title" . }}
<!-- Blocks may include default content. -->
{{ .Site.Title }}
{{ end }}</title>
</head>
<body>
<!-- Code that all your templates share, like a header -->
{{ block "main" . }}
<!-- The part of the page that begins to differ between templates -->
{{ end }}
{{ block "footer" . }}
<!-- More shared code, perhaps a footer but that can be overridden if need be in -->
{{ end }}
</body>
</html>
You could now define a single.html file as follows
thank you both! I don’t entirely get it, but I will play with this basic structure.
I’m trying to create my own theme from scratch, but it seems to be the chicken and egg problem for a start - you need to create your own theme, but to create a new theme you had to have knowledge gained from creating a theme …
Atm I have semi working theme without “baseof” file, just with list , single and custom index. And I’m trying to get a hang of it. Now I’m playing with ranges and looping over them… and getting images to work .
Will try to rebuild it with baseof as well . Will see how it goes - it’s a bit challenging but Hugo seems to be better documented than other generators I’ve tried.
If you want to try building a site without using a theme. You still have to create layouts of course, but this approach might make things easier to begin.