Custom sidebar (left nav menu) entries

I’m relatively new to Hugo, and using the Zdoc theme.
The title of each doc page is taken from the md file metadata, as in this example:

title: "Deploy Core Components on Kubernetes and OpenShift"

This also becomes the left nav menu entry. However, in some cases, it’s too long and repeats information that’s available from the menu context anyway.
Question: How can I modify the Zdoc theme code to search for a “menu_title” in the front matter, and use that in the menu if found? If not found, the “title” item will be found as today.

So in this case:

title: "Deploy Core Components on Kubernetes and OpenShift"
menu_title: "Kubernetes and OpenShift"
  • The menu entry would be “Kubernetes and OpenShift”
  • The title of the page itself would still be “Deploy Core Components on Kubernetes and OpenShift”

Thanks!

The right way to do this is to optionally set linkTitle in front matter.

title = "very very very long"
linkTitle = "short"

The theme’s menu template should be rendering .LinkTitle instead of .Title. If you call .LinkTitle from a template, and linkTitle isn’t set in front matter, the .LinkTitle method falls back to the title field in front matter.

After changing your front matter, if it doesn’t work, contact the theme author.

1 Like

Thanks for your very quick response.
Unfortunately, it did not work, so I’ll ask the theme authors (whoever they might be… can’t find out who).
Any other ideas?

If this is the theme:

https://github.com/zzossig/hugo-theme-zdoc

It is no longer maintained.

Good news! I was able to hack the \themes\zdoc\layouts\partials\main\sections file to make the LinkTitle value appear in the left nav menu.

Before

<a href="{{ .Permalink }}"  class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }} {{ if .Params.SubLevel }} sub-level {{ end }}" data-depth="{{ $depth }}" title="{{ .Title }}">{{ .Title }} </a>
            {{ end }}

After:

          <a href="{{ .Permalink }}"  class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }} {{ if .Params.SubLevel }} sub-level {{ end }}" data-depth="{{ $depth }}" title="{{ .LinkTitle }}">{{ .LinkTitle }} </a> type or paste code here

This works for menu entries for single pages, but not for “folders” that can be collapsed and expanded. I imagine I’ll be able to find and fix that too.

Thank you very much for putting me on the right track!

1 Like

Errata: I meant the file \themes\zdoc\layouts\partials\main\sections\single-menu.html