Why don't .IsMenuCurrent and .HasMenuCurrent work on leaf bundle pages?

Just came across this limitation and I don’t see the reason why it would be this way.

This workaround is ok:

<a {{if eq $page.URL .URL}} class="active" {{end}}>Link to a single page / leaf bundle</a>

However, one can’t use .HasMenuCurrent to check whether a menu entry’s child is active and display accordingly.

The only solution for it to work that I’ve found is to not use a leaf bundle even if it won’t have children pages, just because it has a corresponding menu entry.

  • Is this the intended behavior? If so, shouldn’t we documment it somehow?
  • Why have single pages’ page objects have a .IsMenuCurrent method that does nothing?

Are your menu entries defined in front matter, or in site configuration?

They’re defined in the site’s config.

The use-case I’m referring to is for a menu which contents don’t depend on the current page, and that maps the entire site’s structure(or to a certain depth).

Is this not the ideal approach for this requirement? If not, what would be better?

Thanks!

In your site configuration, use pageref instead of url when referencing pages.

See https://github.com/gohugoio/hugo/issues/9150#issuecomment-965798975

2 Likes

Thank you very much!

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