HUGO

Menus .ByWeight Doesn't work

I am trying different commands to sort my menu by weight but it doesn’t work

Code:

        <ul class="nav-list component-loaded" data-component="nav" role="menu">
            {{ range .Site.Menus.main.ByWeight }}
            {{ if .HasChildren }}
                <li class="menu-item menu-item-{{ .Name | urlize }} menu-level-1 has-submenu menu-item-hover-reveal">
                    <span style="margin-right: 3px">{{.Name}}</span>
                    <ul class="sub-menu" data-{{ .Name | urlize }}-submenu="{{ .Name | urlize }}" role="menu">
                        {{ range .Children.Sort.ByWeight }}
                            <li class="sub-menu-item menu-level-2 primary-style" role="menuitem">
                                <a aria-label="{{ .Name }}" href="{{ .URL }}">{{ .Name }}</a>
                            </li>
                        {{ end }}
                    </ul>
                </li>
            {{ else }}
                <li class="menu-item menu-item-{{ .Name | urlize }}" data-menuitem="{{ .Name | urlize }}" role="menuitem">
                    <a data-component-label="{{ .Name | urlize }}" aria-label="{{ .Name | urlize }}" class="nav-name-{{ .Name | urlize }}" href="{{.URL | absURL}}" class="nav-link">{{.Name}}</a>
                </li>
            {{ end }}
        {{ end }}
        </ul>

Menu Code:

  [[main]]
    name = "Home"
    url = "/"
    weight = 1

  [[main]]
    parent = "Guide"
    name = "Guide 1"
    url = "/guide-1/"
    weight = 2
    
  [[main]]
    parent = "Guide"
    name = "Guide 2"
    url = "/guide-2/"
    weight = 2

  [[main]]
    name = "Blog"
    url = "/blog/"
    weight = 3

How to Resolve???

What does that mean?

2 Likes