Skip to content
/ Ekko Public
forked from laravelista/Ekko

Laravel helper that detects active navigation menu items and applies bootstrap classes.

License

Notifications You must be signed in to change notification settings

erenilhan/Ekko

 
 

Repository files navigation

Ekko

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

Ekko

Laravel helper that detects active navigation menu items and applies bootstrap classes.

I reuse this code across many projects so I wanted a central place for it.

Installation

First, pull in the package through Composer.

"require": {
    "laravelista/ekko": "~1.2"
}

And then, if using Laravel 5 or 4, include the service provider within app/config/app.php.

'providers' => [
    'Laravelista\Ekko\EkkoServiceProvider'
];

And, for convenience, add a facade alias to this same file at the bottom:

'aliases' => [
    'Ekko' => 'Laravelista\Ekko\Facades\Ekko'
];

Usage

You would most likely use this package in your navbar partial like so:

<li>
    <a href="{{ route('home') }}" class="{{ Ekko::isActiveRoute('home') }}">
        <i class="halflings white home"></i> Home
    </a>
</li>

<li>
    <a href="#" class="{{ Ekko::areActiveRoutes(['murter', 'kornati']) }}">
        <i class="halflings white screenshot"></i> Location
    </a>
    <ul>
        <li>
            <a href="{{ route('murter') }}">Murter</a>
        </li>
        <li>
            <a href="{{ route('kornati') }}">Kornati</a>
        </li>
    </ul>
</li>

<li>
    <a href="{{ route('trips.index') }}" class="{{ Ekko::isActiveMatch('trips') }}">
        <i class="halflings white road"></i> Trips
    </a>
</li>

API

As the second parameter to any method, you can pass the value you want to get returned if there was a match. By default this is active which is Bootstrap default.

isActiveRoute($routeName, $output = "active")

Compares given route name with current route name.

{{ Ekko::isActiveRoute('home') }}

The * wildcard can be used for resource routes.

{{ Ekko::isActiveRoute('user.*') }}

isActiveURL($url, $output = "active")

Compares given URL with current URL.

{{ Ekko::isActiveURL('/about') }}

isActiveMatch($string, $output = "active")

Detects if the given string is found in the current URL.

{{ Ekko::isActiveMatch('bout') }}

areActiveRoutes(array $routeNames, $output = "active")

Compares given array of route names with current route name.

{{ Ekko::areActiveRoutes(['product.index', 'product.show']) }}

The * wildcard can be used for resource routes, including nested routes.

{{ Ekko::areActiveRoutes(['user.*', 'user.comments.*']) }}

areActiveURLs(array $urls, $output = "active")

Compares given array of URLs with current URL.

{{ Ekko::areActiveURLs(['/product', '/product/create']) }}

About

Laravel helper that detects active navigation menu items and applies bootstrap classes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%