Is there a way to dynamically populate a "nav" section with links?

I would like to store them in a json file.

See https://gohugo.io/templates/data-templates/. For example…

data/menus.json

{
  "main": [
    {
      "name": "Foo",
      "url": "/foo/"
    },
    {
      "name": "Bar",
      "url": "/bar/"
    }
  ],
  "footer": [
    {
      "name": "Baz",
      "url": "/baz/"
    },
    {
      "name": "Quez",
      "url": "/quez/"
    }
  ]
}

layouts/partials/header/nav.html

{{- range .Site.Data.menus.main -}}
  <a href="{{ .url }}">{{ .name }}</a>
{{- end -}}

layouts/partials/footer/nav.html

{{- range .Site.Data.menus.footer -}}
  <a href="{{ .url }}">{{ .name }}</a>
{{- end -}}

Can we also dynamically populate JSON files?

Yes! See:

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