-
Notifications
You must be signed in to change notification settings - Fork 194
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
is there any way to get previous and next menu items with respect to the current page (menu) item opened ? #210
Comments
Hi, it's exactly what I'm trying to do ! I think we should use iterators in KnpMenu, see "Filtering only current items". I installed KnpMenuBundle and created my menu as a service, then in my default controller, I test this :
But I have a Symfony error : So I add these lines at the beginning of my controller :
But I still have this error. I don't understand... Anyway! After get items infos according to the current page, we could use php functions prev() and next() to find what we want. Here is a simple example which works for me. Instead of using a "manual array", we should be using the structure array of our KnpMenu.
In a twig file :
With KnpMenu array, we could replace "Previous" and "Next" with items labels. Please, help us to find a solution ! |
You are missing |
Ok thanks... I test this :
$menu is a Knp\Menu\MenuItem object, here is what it looks like :
So I have all informations that are useful for me, but iterator seems to not work. |
If you click on the "edit" symbol on the top left corner of the article, you can correct it and submit a PR. Can you please do that?
To be more precise, echo isn't executed. This is because you're instantiating a matcher without any voters. This way, there is no logic that votes if a menu item is current or not, so no item is marked as current. You have to enable at least one voter. Take a look at the |
Well, you should not create a new matcher but get the one registered as a service. Otherwise your matcher will not have any voter configured, and so won't match any item as current |
Ok, no problem.
How can I do that ? Maybe I could use my menu item object I don't understand what are voters but maybe I don't need finally to use them... |
Replace the line with |
The idea that I had works. But the only inconvenient is that I have to list manually the association url => item name.
Twig
|
EDIT : 2016-04-15 Ok, I found the solution with matcher and iterators. DefaultController.php
Is it possible to find the routeParameter of a menu item easier than below ? Twig
This code shows only children pages of "my-section". Hope it helps ! ;-) |
I edited my last post, few errors and I added index page in the loop. |
@eved42 i would like to close this issue if its solved for you. would be great to provide this example in the documentation. maybe you could do a pull request to add a doc/05-cookbook.md file and add this there, starting with explaining what you want to achieve and then what you have here. |
Hi,
This is common requirement in blogging that when user is on current page, we need to add previous and next links.
Is there any way to get previous and next menu items with respect to the page opened ? Something like,
knp_menu_render('menu', {'next': 1});
The text was updated successfully, but these errors were encountered: