Menus not populated


#1

Hi all,
first of all, thanks for Hugo!
I have a problem with my menus: they are not populated.
I put in my config.toml:

sectionPagesMenu = "main"

My website has a lot of sections, I can see them with:


 {{ range .Site.Sections }}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
    {{ range .Sections }}
       <li class="active">
          <a href="{{ .URL }}">{{ .Name }}</a>
       </li>
    {{ end }}
{{ end }}

Yelds all the subsections:

WAZIUP Tutorials
LoRa sensing and gateway
Build IoT apps with Waziup
Tutorials
Support
Documentation
How Waziup works?
API Reference
Waziup platform User Guide
Why use WAZIUP? 

But using menus doesn’t work.

{{ $currentPage := . }}
{{ range .Site.Menus.main }}
     {{ if .HasChildren }}
         <li class="{{ if $currentPage.HasMenuCurrent "main" . }}active{{ end }}">
            <a href="#">
                {{ .Pre }}
                <span>{{ .Name }}</span>
            </a>
         </li>
         <ul class="sub-menu">
           {{ range .Children }}
              <li class="{{ if $currentPage.IsMenuCurrent "main" . }}active{{ end }}">
                  <a href="{{ .URL }}">{{ .Name }}</a>
              </li>
           {{ end }}
         </ul>
     {{ else }}
          <li>
              <a href="{{ .URL }}">
                 {{ .Pre }}
                 <span>{{ .Name }}</span>
              </a>
          </li>
     {{ end }}
{{ end }}

Yelds only 3 (unrelated) subsections:

Documentation
LoRa sensing and gateway
Support 

The source of the website is here: https://github.com/Waziup/waziup.io/tree/hugo


#2

It works with front matters:

menu:
    main:
      title: foo
      parent: bar
      weight: 4

But using the “Section Menu for Lazy Bloggers” method doesn’t work.
Probably because my pages are nested (sections inside sections inside sections).


#3

I am having the same problem with my new site

source for site

https://github.com/davsk/hugo-website

source for theme

https://github.com/davsk/hugo-theme-davsk

:weary:


#4

I find that the HTML for the pages is being generated but the HTML for /blog/index.html has errors.

I had created 3 posts in /blog/ but this page just has three empty <span>

<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">www.Davsk.com</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">Home</li>
      </a><a href="/blog/">
        <li class="mobile-menu-item">Blog</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">Categories</li>
      </a><a href="/events/">
        <li class="mobile-menu-item">Events</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">Tags</li>
      </a><a href="/help/">
        <li class="mobile-menu-item">Help</li>
      </a>
  </ul>
</nav>

#5

@comaldave from your website, which template/partial is used to generate the HTML you gave?


#6

I don’t know! I think I know but I am new at this.

First I checked what the browser received.

view-source:http://www.davsk.com/blog/

The project is organized into a primary repo with submodules for:
  • public so that site can be served from root of master
  • content so that I can authorize family members to use GitHub to add posts.
  • each of the themes in the themes directory, one of which is the one I am creating.

The file being served may have been changed by JS on the browser but I still see the same errors.

https://github.com/davsk/www.davsk.com/blob/master/blog/index.html

I am thinking that the file was generated using the contents of /layout/ but layouts is an empty folder.

https://github.com/davsk/hugo-website

This means that it must be coming from the selected theme.

https://github.com/davsk/hugo-theme-davsk/tree/master/layouts/partials

This is a fork of another theme which seemed to be working. I have not made many changes yet.

partials/blog is a copy of partials/post

Thank you for looking at this for me. I have started a new bare site and am going through the tutorial again, hoping I make fewer mistakes.


#7

Problem Solved for me

my son also uses Hugo. He replaced my theme with his theme and every thing works. He also tested it with a theme by spf13 and it worked fine. He suggested that I use a theme that works, and if I want to create my own theme:

Use something from spf13 as your baseline for being able to say “I know it works with hugo’s author’s own theme, so this issue must be with this theme”.
Sorry this does not solve your problem but it may give you an idea of how to identify it.


#8

OK, great to hear.
I suggest that you import your style elements one by one into your working base theme.