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

Feature request - Access page context from menu context #2784

Closed
kamar535 opened this issue Dec 13, 2016 · 4 comments
Closed

Feature request - Access page context from menu context #2784

kamar535 opened this issue Dec 13, 2016 · 4 comments

Comments

@kamar535
Copy link

The only variables accessible when rendering a menu item are listed here https://gohugo.io/extras/menus/#what-is-a-menu. It would be great if there was a way to access the page context of the current menu item when rendering the menu.

Motivating example

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.

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.

Initial discussion here https://discuss.gohugo.io/t/get-page-variables-from-menu-context/4812/2

@inlandsee
Copy link

+1. For the sake of clarity it would be nice to add custom menu vars as desired then access them during render. At present MenuEnttry ignores the custom style/icon' vars in the example below. I can fake it by passing them as pre and post but the code is hard to understand and any additional custom vars require additional monkey business.

+++
#menuentry ignores style/icon, must pass as pre/post
[menu.user]
parent="account"
style="dialog"
icon="fa-sign-in"
+++

@martinburger
Copy link

I would prefer @inlandsee's solution.

Rationale: As far as I understand, "a menu item isn't connected to a page, so I don't think there is a easy way to get to a menu item's page's parameter". [related Hugo Discussion]

Attaching custom attributes to menu entries would be great.

@stale
Copy link

stale bot commented Dec 6, 2017

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants