Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Hero support submenu in nav-bar? #15

Closed
Bp3289 opened this issue Jul 30, 2019 · 4 comments
Closed

Does Hero support submenu in nav-bar? #15

Bp3289 opened this issue Jul 30, 2019 · 4 comments

Comments

@Bp3289
Copy link

Bp3289 commented Jul 30, 2019

Hi,

I am currently using the hero theme for hugo. I've been trying to add a dropdown menu in the navbar. I've seen from other themes that they use a "submenu" and use the parent and children identifier in the config.toml. I've also seen some people suggest the reason submenu isn't working for them is because their theme doesn't support it. I can't find any documentation for the hero theme to tell if it supports submenu. I wanted to ask just in case it's not supported for hero theme.

Best,
William

@Bp3289
Copy link
Author

Bp3289 commented Jul 31, 2019

Ended up building one, so it is possible! Closing out issue

@Bp3289 Bp3289 closed this as completed Jul 31, 2019
@JugglerX
Copy link
Collaborator

Im glad you got it done. If your repo is public can you share the link, this is quite a common request.

@Bp3289
Copy link
Author

Bp3289 commented Aug 1, 2019

Unfortunately the repo is private, however I can explain how I made it work.

First off, I had to edit my config.toml.

There is an "identifier" property you can throw in. Then for whatever you want inside the dropdown, you need to add the property called "parent", like so:

`[[menu.main]]
name = "Resources"
identifier = "resources"
weight = 3

[[menu.main]]
name = "Blog"
parent = "resources"
url = "/blog/"`

Then in the html there is an "HasChildren" and "{{range .Children}}" properties that will need to be added, like so:

<ul> {{ $currentPage := . }} {{ range .Site.Menus.main }} {{ if .HasChildren }} <div class="dropdown"> <button class="dropbtn">Resources <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> {{ range .Children }} <li class="{{ if $currentPage.IsMenuCurrent "main" . }}active{{ end }}"> <a href="{{ .URL }}">{{ .Name }}</a> </li> {{ end }} </div> </div>

That's how I was able to get it working. Cheers!

@firebone-be
Copy link

firebone-be commented Nov 18, 2022

@Bp3289
I know this post is a bit old but I am also looking to add submenus.

I tried adjusting the layouts/partials/main-menu.html but I am messing up somewhere.

This is what I have:

<div id="main-menu" class="main-menu">
  <ul>
    {{ $currentPage := . }}
    {{ range .Site.Menus.main }}
      {{ if .HasChildren }}
        <div class="dropdown"> <button class="dropbtn">Resources <i class="fa fa-caret-down"></i> </button>
          <div class="dropdown-content"> {{ range .Children }} 
            <li class="{{ if $currentPage.IsMenuCurrent "main" . }}active{{ end }}"> 
              <a href="{{ .URL }}">{{ .Name }}</a> 
            </li>
      {{ end }}
        </div>
      </div>
    </ul>
  </div>

But getting unexpected eof error...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants