Where to define menus?

Hi, I’ve been reading the documentation and see the section on menus but I’m not sure where to put the definition. The formatting doesn’t look like it belongs in the TOML file… Does it?


I put the menu definition in my config.yaml and it works. Of course, config.toml and config.json are also ok.

Oh I see. I was just looking at the documentation which shows YAML (and then later TOML) and didn’t realize you could do either.

It later goes on to mention the config file too. Can menus be defined elsewhere?


According to the code, you can put a menu definition in a front matter of each page.

Make sure you read http://discuss.gohugo.io/t/intro-to-toml/42/4, it has some useful information about TOML that took me a while to figure out.

In the front matter of each content page you want in the menu, I have something like this:

date = "2014-09-18T21:51:13+02:00"
title = "About Us"
name = "About"
weight = 4

One important thing to remember is that all table definitions in TOML needs to be last, since it just keeps adding variables that appears until the end or until the next table definition. If name in [menu.main] is left out, it will use the page title. weight is for determining the order of your menu items.

Then my partials/nav.htmlis something like this:

		{{ range .Site.Menus.main }}
		<li><a href="{{ .Url }}">{{ .Name }}</a></li>
1 Like

@oscar_b: modified your above post to change “array” to “table”, since that’s the more correct term for what menu is, in this case. An array is traditionally a list of the same thing, like fruit = ["pear", "apple", "orange"] whereas a table in toml is like a hashtable, or dictionary in other languages (or object in json) - a separate thing with it’s own name/value pairs.

Hope you don’t mind, just wanted to make sure the terminology was correct.

Not at all, thanks :slight_smile: