I’m working through Mr. Hogan’s book, and the code has been running fine, until I got to the section “Using Content Blocks and Partials” in chapter 2. When I substituted the following code for ‘index.html’, I got a blank output:
{{ define “main” }}
{{ .Content }}
{{ end }}
Hugo didn’t give any error messages, just blank output. If I commented out the above code, and restored the previous html, I would get output. Also, I found I would get wonky results if I copied and pasted from the PDF, so I typed this code by hand, and still no output. What do I need to do to get output from Hugo using ‘partial’ blocks?
I have installed Hugo 0.77 on Windows 10 (64-bit). Thanks!
I just went through chapter 2 again with the latest Hugo and was able to follow the book, but I have had some others have interesting issues happening.
First, what text editor are you using? I have seen some text editors with “auto formatting” tools (VSCode) make really subtle changes to Hugo template files. Make sure that when you save you don’t see any spaces introduced or removed. Someone struggled for days with that till we figured it out.
But beyond that…
{{ define "main" }}
{{ .Content }}
{{ end }}
is correct for that page, provided it’s in themes/basic/layouts/index.html.
That should be the only content in the file though. All the rest of the content should be gone.
What’s your themes/basic/layouts/_default/baseof.html file look like? We might find an issue there.
“That should be the only content in the file though. All the rest of the content should be gone.”
Actually, I had a comment in the file, along with the code I provided above. And when I removed that comment, the output magically reappeared! I really had no idea that the presence or absence of a comment would make such a difference.
Do other files in Hugo respond this way to comments? I may have to do some experimenting to find out. In any case, thank you for taking the time to respond; it really helped!
As for comments, you can have certain kinds of comments in some of your files, but Hugo really hates HTML comments if they are at the top of the file in your templates.