I have a Hugo site that I have been working on for a while. It has a navigation menu at the top that is rendered from the config.toml.
Following guidance from the Hugo docs I have the following code.
[menu]
[[menu.main]]
name = "Page 1"
url = "/page-1"
weight = 1
[[menu.main]]
name = "Page 2"
url = "/page-2"
weight = 2
[[menu.main]]
name = "Page 3"
url = "/page-3"
weight = 3
[[menu.main]]
name = "Page 4"
url = "/page-4"
weight = 4
Above is the menu inside the config.toml file.
To render this in the nav bar I used the following code:
<nav>
{{ range .Site.Menus.main }}
<a href='{{ .URL }}' class="nav-links">
{{ $text := print .Name | safeHTML }}
{{ $text }}
</a>
{{ end }}
</nav>
This code has been working absolutely fine up until I came to work on it this morning.
The problem now is that the nav element is rendering just blank there are no elements inside.
I tried using the following code on my page to determine if it was reading the config menu elements in properly or not.
{{ printf "%#v" .Site.Menus }}
But this return the following text:
navigation.Menus{}
Which shows me that none of the elements from the config file are being rendered.
After looking around I could only find this issues in a few places and all of them were down to the partial not having a "." in it to provide scope, however my partial is rendered as such:
{{- partial "header.html" . -}}
I have also tried it like this:
{{ partial "header.html" . }}
But neither are working now.
What I find most confusing is this was working yesterday but not this morning when I came back to it. I have tried removing all changes from yesterday and it didn't make a difference.
I also tried going back to master branch (which is nearly two weeks older) before I even started making any changes to the site on my current branch and now that old version is also not rendering the menu elements even though it was completely fine previously.
I am hoping anyone might have some suggestions about something I haven't tried or if I am just missing something entirely.
Edit: unfortunately I never worked out what this problem was, returning to my desktop seemed to have fixed the issue and I have since been back to my laptop and it didn't have it either. I am chalking it up to some confused code or settings that wasn't generating the site properly, sorry there isn't an answer for anyone else that comes across this.