Coder Social home page Coder Social logo

ekko's Introduction

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']) }}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.