Add custom meta data to menu entry

I was wondering if it is possible to add custom meta data to menu entries… Well, not exactly wondering, I tried and failed:

[[menu.main]]
name = "44"
weight = 250
identifier = "fourtyfour"
url = "https://fourtyfour.space"
pre = "<i class='fas fa-unicorn fa-fw'></i>"
target = "_blank"

Only this one single menu entry has the target key.
In the templates then I though it might be possible to run with it like this:

<a href="{{.URL}}" class="nav-link" target="{{ .Target }}">{{ .Pre }}&nbsp;{{ .Name }}</a>

But it’s not working and throwing a 5 exception error tantrum (about “can’t evaluate field Target in type *navigation.MenuEntry”).

Is there really no way to add custom information to menu entries via config.toml? How would you try to implement this “feature” (some menu links open new windows, not all)?

By the way, the a-href-line is my latest code. I tried with around the target - not working either.

When I need something unique for a menu entry I typically check its name:

 {{- range .Site.Menus.main -}}
<a href="{{ .URL }}"{{if eq .Name "some-name" }} target ="_blank"{{ end }}>{{ .Name }}</a>
  {{- end -}}

This can be adapted to check for the menu entry’s identifier as well.

1 Like

Hmmm… that’s not really reusable (as in “put it in a theme”)… But I am having an idea :wink: Putting the names with unique targets into the config file and then ranging through it. I’ll try that one.

Another “trick” would probably be to check the URL for http(s) in the beginning.

1 Like