Get page variables from menu context

Is it possible to access page variables when rendering the menu? For example, if a page has the following front matter,

---
title: Title
foo: my-foo
---

, from the menu.html template, is it possible to access the foo page variable when rendering the the menu item for the page.

The only variables accessible when rendering a menu item are listed here https://gohugo.io/extras/menus/#what-is-a-menu. Maybe it is possible to look up the page context using the URL menu variable?

I want to access the foo page variable both when rendering header.html and when rendering menu.html to decorate the page title and the menu item depending on the value of foo.

No, but it should – and is even more relevant now that “everything is a page” (Hugo 0.18).

It should be easy to add – could you create an issue on GitHub about it?

GitHub issue created https://github.com/spf13/hugo/issues/2784

1 Like