Can't render the menu from the config.json

So I wanted to make my nav menus Hugo like. But I don’t know what is wrong with my code that doesn’t render menus from config. So here is My header.html
`

{{ range .Site.Menus.main }}

<a href="{{ .URL }}">{{ .Title }}</a>

{{ end }}
` And here is my `config.json`

`
“menu”: {

        "main": [

           {

              "name": "Blog",

              "url": "/blog/"

           },

           {

            "name": "Blog",

            "url": "/blog/"

           },

           {

            "name": "Blog",

            "url": "/blog/"

         },

         {

          "name": "Blog",

          "url": "/blog/"

         },

         {

            "name": "Blog",

            "url": "/blog/"

        }

        ]

     }

`

There is no error but nav doesn’t show anything.

View source in the broswer, or inspect with browser dev tools. You will probably see your anchor elements, but without content between the opening and closing tags.

.Title

string Link title, meant to be used in the title attribute of a menu entry’s <a> -tags. Returns the menu entry’s title key if set. Else, if the menu entry was created through a page’s front-matter, it returns the page’s .LinkTitle . Else, it just returns an empty string.

See https://gohugo.io/variables/menus/#menu-entry-functions

Try this instead:

{{- range .Site.Menus.main -}}
  <a href="{{ .URL }}">{{ .Name }}</a>
{{- end -}}
2 Likes

Thanks, It worked.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.