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

current or active route.. #2

Closed
pablomaurer opened this issue May 23, 2014 · 11 comments
Closed

current or active route.. #2

pablomaurer opened this issue May 23, 2014 · 11 comments

Comments

@pablomaurer
Copy link

didn't search for it, but anyway a built in solution for current or active menu-item would be great...

An really this one is the best menu Builder for Laravel out there !! Thanks for making it =)

@lavary
Copy link
Owner

lavary commented May 23, 2014

I'm actually working on this feature and will push it up today.

Thanks for the comment :)

@pablomaurer
Copy link
Author

That will be great =) just fell in love with you 😝

@lavary
Copy link
Owner

lavary commented May 23, 2014

haha. I'm glad you like the package :)

@Fuhrmann
Copy link

Fuhrmann commented Jun 2, 2014

Yeah, that would be nice. =)

@leek
Copy link

leek commented Jun 3, 2014

I accomplished this by wrapping my menu in a Route filter, e.g.:

Menu::make('myMenu', function($menu) {

    Route::filter('myFilter', function($route, $request) use ($menu) {
        // $route is the current route
        $someParameter = $route->getParameter('someParameter');

        $menu->add('Link', ['route' => ['someRouteName', 'someParameter' => $someParameter]]);
    });

});

@lavary lavary closed this as completed Jul 15, 2014
@pablomaurer
Copy link
Author

My solution if maybe somebody else is interested:

    $createMenu = function($guestMenu) {
        $guestMenu->add(trans('menu.dashboard'), array('route'  => 'dashboard'));
        $guestMenu->add('Produkte', array('route'  => 'dashboard'));
    };
    $guestMenu = Menu::make('mainNav', $createMenu);

    // here is the filter to find the active item
    $guestMenu->filter(function($item) {
        if(route($item->link->path['route']) == Request::url()) {  // but then all items must have a route
            $item->active();
        }
        return true;
    });

@dustingraham
Copy link
Collaborator

I did something similar to mnewmedia:

->filter(function($item)
{
    // Check if route is active.
    if (Request::url() === rtrim($item->url(),'#/'))
    {
        $item->active();
    }

Sometimes I'd like to mark an item as active when the user is in a sub-path so I might adjust this at some point to allow some sort of wildcard matching, but for now this works.

@leek
Copy link

leek commented Jul 29, 2014

@mnewmedia / @dustingraham - You guys should check out Request::is() which allows wildcard URL matching.

Example:

Request::is('foo/*');

@lavary lavary reopened this Jul 29, 2014
@dustingraham
Copy link
Collaborator

@leek Yes, I'm using Request::is in another system. It just didn't seem to fall in to place here. We may need another parameter in the menu->add function for active url match or something to that effect.

@lavary
Copy link
Owner

lavary commented Aug 3, 2014

dev-master now automatically activates items and all parent nodes according to the current URI

Instead of relying on wildcard URL matching for activating parent nodes, I used Request:path() and and a recursive function to mark the parent nodes as activated; The reason is that some parent nodes might not have any URL defined.

You can choose which item to be activated (Item or Link) in options.php which resides in the package config/ directory.

<?php
// ...
'active_element' => 'item',    // item|link
// ...

@pablomaurer
Copy link
Author

oh what damn fantastic create news =)

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