Making a basic theme with a navbar menu and the first menu item is not visible

I defined a menu in config like this;

name = 'Home'
pageRef = '/'
weight = 10

name = '/about'
pageRef = '/about'
weight = 20

name = '/blog'
pageRef = '/blog'
weight = 30

name = '/cv'
pageRef = '/cv'
weight = 35

name = '/uses'
pageRef = '/uses'
weight = 40

Then wrote a range in layouts/partials/header.html like this;

{{- with site.Menus.main -}}
<nav class="navbar" role="navigation" aria-label="main navigation">

  <div class="navbar-brand">
    <a href="/" class="navbar-item">{{ site.Title }}</a>

  <div id="navbarBasic" class="navbar-menu">
    <div class="navbar-end">
      {{- range . -}}
      {{- if $.IsMenuCurrent .Menu . -}}
      <a href="{{ .URL }}" class="is-active navbar-item" aria-current="page">{{ .Name }}</a>
      {{- else -}}
      <a href="{{ .URL }}" class="navbar-item">{{ .Name }}</a>
      {{- end -}}
      {{- end -}}
{{- end -}}

And the menu works except it doesn’t show the first item. What am I doing wrong?

I am unable to reproduce the problem as described. Try it:

git clone --single-branch -b hugo-forum-topic-49368 hugo-forum-topic-49368
cd hugo-forum-topic-49368
hugo server

I cloned that branch and it shows the exact same problem for me, the first menu item “Home” is not displayed.

And the menu is defined identically as mine of course.

I’m using Firefox 124.0.1 on Fedora Sericea 38. But I also tried in Chromium which I have installed and it shows the same issue. So I don’t think it’s worth trying FF in safe mode. My chromium is very vanilla, only have it to run work stuff like Teams and Outlook.

I’ve published the theme here on gitlab in case anyone can tell what I’m doing wrong. It’s based on the default hugo template when you create a new theme, I just modified a few files so far.

Yes, it is.


Menu entries define a menu. They do not define a page collection.

Ok I see I read the wrong place, confused the pages with the menu. But I still can’t get it to work on my own theme. It’s here on gitlab if you want to take a look.

I’d be happy to look at a test site that includes your theme, but working with the theme alone is insufficient for troubleshooting your issue.

You’ve defined the menu entries twice in your site configuration. The last one wins.

Yeah thanks! I just found it and came here to hang my head in shame.

1 Like

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