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

Render menu containing only siblings of active menu item #153

Open
bkosborne opened this issue Jun 11, 2014 · 5 comments
Open

Render menu containing only siblings of active menu item #153

bkosborne opened this issue Jun 11, 2014 · 5 comments

Comments

@bkosborne
Copy link

I'm curious, is there a way to render a partial menu containing siblings (and maybe children) of the current menu item?

Given a menu tree:

Items
--> Bat
--> Ball
------> Large Ball
------> Medium Ball
------> Small Ball
--> Bottle

If the user is on the Large Ball page, I'd like to be able to render all siblings. In my real case, they would be rendered as tabs.
#84 may be the same thing, but it seems like that use case is actually rendering all the ancestors as well.

It seems I can do this:

{{ knp_menu_render(['AcmeDemoBundle:Builder:mainMenu', 'Items', 'Ball']) }}

But that would require that I know the name of the current menu item. If I can get that in twig somehow, I guess that would be fine and I could just fill it in there, but ideally there'd be some baked in functionality to support rendering sub-trees.

@Nek-
Copy link
Contributor

Nek- commented Jun 12, 2014

Can you give an example where it can be useful ?

I'm trying to imagine "why".

Notice that there's an easy way to do but we were talking about deleting it because it's a problem in the code to implemente more cool things.

@bkosborne
Copy link
Author

Sure. I want to limit my main nav bar to just show two levels of depth in the menu, but the menu may be much deeper. When someone is on one of those pages, I want to introduce another navigation in a sidebar that contains the remaining pages.

Here's an example of a website that does it: http://www.bu.edu/cs/undergraduate/computer-science-major

The main menu on the top contains two levels of items. But if you click on Undergraduate for instance, there's a new nav on the right that contains remaining children.

@sschueller
Copy link

Has anyone figure out how to do this or is a custom template required? It appears I can limit the depth in using the depth option but I can not start at a specific depth. With knp_menu_get_current_item() I can start at the depth of the current page but I would like to always start the second depth of the root. Also what does matchingDepth actually do? I can't find any doc on it and it appears to do nothing at all.

@SevenbitsIt
Copy link

I also need this and it seems there is no really alternative to knpmenu on symfony. I also can't find out what matchingDepth does. Has anyone found a solution in this 5 years the bug is open now?

@garak
Copy link
Collaborator

garak commented Oct 8, 2020

I also can't find out what matchingDepth does.

See https://github.com/KnpLabs/KnpMenu/blob/master/doc/01-Basic-Menus.md#other-rendering-options

matchingDepth: The depth of the scan to determine whether an item is an ancestor of the current item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants