.
├── _index.md
├── section1
│ ├── bar
│ └── foo
└── section2
├── bar
└── foo
I want to achieve two things:
In each page that inherits baseoff.html, I want to get the name of the “section”, in the sense that here, a section is either Section 1, Section 2, or the home page.
I want to create a nav bar with urls to the home page and the two sections.
I tried to play with this blog entry, but did not manage anything.
Thanks a lot to both of you. This way of doing the menu is brilliant. I just had to change pageRef = ... to url = ... to make it work (thanks to this page in the docs).
For the {{ .Section }}, the problem is that the homepage/index is not considered a section. Therefore, {{ .Section }}is empty on the homepage. Furthermore, when in a section, this syntax does not allow to use the title given in section1/_index.md or section2/_index.md.
P.-S. : @jmooring you helped me the other day on this topic, and just so you know, I made the FAQ as you advised. I am now very happy with this solution.
This is how I do my menus. In every section/page I want to appear in the menu (I have header and footer menus) I add something like this in the _index.md or the page frontmatter
Then range over the menus using an example similar to the example shared by @jmooring . For footer menu, I change main to footer in the code.
In your case you can replicate the same in the _index.md at the root of content and for section1 and section2 (and remember to change the weight depending on the preferred order in the menu).
BTW, Hugo is versatile and I have seen about 4 ways to create menus with it.