Dynamic menu

probably a very basic question but I’m trying to make a dynamic menu for the sidebar of a site.
I have a few top level sections

- section1
- section2
  |- section2.1
  |- section2.2
  `- section2.3
     |- page2.3.1
     `- page2.3.2

I only want the menu when I’m on a page or section within section 2 to include items from 2.x onwards
the template at the moment uses {{ $currentNode := . }} to get the top level, so I’m thinking I need to change this to something like {{ $currentNode := .Site.Sections.section2 }} but I can’t find any reference to the syntax to do that.

any idea? and sorry for the probably very basic question!

Hi,

You can use the .Section page variable:

{{ if eq .Section "section2" }}
menu code
{{ end }}

… or use a different layout for section2: Hugo's Lookup Order | Hugo

Try .GetPage instead:

{{ $section2 := site.GetPage "/section2" }}