SectionPagesMenu is not working as a second menu

Hi all,

I’m working on my site with two menus. One for all sections in /content (menuArt), and the second one for special root pages or external links (menuTop).

I cannot make it :(((

All the following in config.toml:

I started using the lazy bloggers menu

SectionPagesMenu = "menuArt"

then I define the menus that I will need:

menu = ["menuArt","menuTop"]

then I define the second menu

[menu]
  [[menu.menuTop]]
  name = "Goto external link"
  url = "https://externallink.com"
  
  [[menu.menuTop]]
  name = "Make contact"
  identifier = "/contact"
  url = "/contact"

My content section is as follows:

content/
   support-patients
   help-doctors
   info-RD

All root sections have a _index.md file.

I use baseof.html.
In my template index.html, I call {{ partial "footer.html" . }} where then I iterate:

<div>
   <ul class="">
      {{ range site.Menus.menuArt }}
         <li><a class="" href="{{ .URL }}">{{ .Name }}</a></li>
      {{ end }}
   </ul>
</div>

All I get is <nil>

I’m baffled.I have read some posts here that report that SectionPagesMenu is not working.

I have tried without SectionPagesMenu = "menuArt" in config.toml, but menus individually defined in this file and it works, but then what is the point of this great feature?


Another related question. If I put all my menus in a menus.toml for a theme that I am developing, where is canonical place to put the file? In the root of my project, next to config.toml? or the theme/config directory? or in a /config directory?

My hugo version is hugo v0.89.4+extended linux/amd64 BuildDate=unknown in Manjaro.

1) Configuration keys are converted to lowercase internally. Use snake_case for all configuration keys, or remember to use lower case when you access them.[1]

2) This doesn’t do anything. Remove it:

menu = ["menuArt","menuTop"]

3) Place menus.toml adjacent to config.toml in the theme’s config/_default directory. Inside of menus.toml, do not repeat the menus key. Example:

config/_default/menus.toml

[[top]]
name = 'About'
pageref = '/about'
weight = 1

[[top]]
name = 'Contact'
pageref = '/contact'
weight = 2

  1. Hugo’s case-sensitivity when accessing configuration or front matter is inconsistent. For example, you can define a front matter field named aBc and then access the field with .Params.abc, .Params.ABC, .Params.aBc, etc. But you cannot do the same thing with menus. So, to prevent future frustration, I recommend using snake_case for all keys. ↩︎

Hi, @jmooring!

Thanks for your help. Here are my findings:

  1. That was it! Once I converted the config value of sectionPagesMenu key to lowercase, it worked! The second menu works, too. I removed the [[menu.]] prefix for each item. However, if the second menu has children items (nested menu), it DOES need the [[menu.]] prefix in each menu item !!!
  2. I removed the line menu = ["menuart","menutop"], although it is mentioned in the Docs (Menus | Hugo). Besides, the example there does not help either, because it doesn’t show how both keys (both menus) work in action (syntax and so).
  3. It doesn’t work to have the menu keys neither in the theme’s config/_default/menus.toml nor in the site’s /menus.toml. The second menu only work when in the /config.toml file.

So far I can reach both menus using {{ range .Site.Menus.menuart }} and {{ range .Site.Menus.menutop }} directives. BUT only when they are in the config.toml.

I cannot figure out what I am missing to make menus.toml to work.


On the other hand, why are double square brackets needed with menu items, but this syntax does not work for params nested values (my own defined values, for example)?

I mean:

[menu]
[[top]]
identifier="menu-item-1"
...
[[top]]
identifier="menu-item-2"

but not

[params]
[params.carousel]
title_carousel="A heading for carousel widget"

Here’s an example with the menus defined in menus.toml.

git clone --single-branch -b hugo-forum-topic-36105 https://github.com/jmooring/hugo-testing hugo-forum-topic-36105
cd hugo-forum-topic-36105
hugo server

See https://toml.io/en/v1.0.0#array-of-tables

1 Like

You are so nice. Thank you!!! :hugs:

I have noticed you also answered me on my first post. First of all, thanks for your both advises. And second, thanks for the effort you took to help me understand with this example of yours.

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