All Projects → laravelista → Ekko

laravelista / Ekko

Licence: mit
Framework agnostic PHP package for marking navigation items active.

Projects that are alternatives of or similar to Ekko

Laravel Alert
A Bootstrap alert helper for Laravel
Stars: ✭ 110 (-60%)
Mutual labels:  laravel, bootstrap
Adminlte Laravel
A Laravel 5 package that switchs default Laravel scaffolding/boilerplate to AdminLTE template and Pratt Landing Page with Bootstrap 3.0
Stars: ✭ 1,814 (+559.64%)
Mutual labels:  laravel, bootstrap
Laravel Coreui Vue
Laravel 5.6 with CoreUI (VueJS Full Starter Template) >>> Deprecated, please go to https://coreui.io/laravel/
Stars: ✭ 132 (-52%)
Mutual labels:  laravel, bootstrap
Wl Bootstrap
Integrating Laravel into WordPress
Stars: ✭ 54 (-80.36%)
Mutual labels:  laravel, bootstrap
Library Management System
📚 An automated library management system developed in Laravel 4.2 PHP MVC Framework
Stars: ✭ 189 (-31.27%)
Mutual labels:  laravel, bootstrap
Laralack
A Slack clone written in PHP & Laravel framework
Stars: ✭ 82 (-70.18%)
Mutual labels:  laravel, bootstrap
Has Parameters
A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.
Stars: ✭ 149 (-45.82%)
Mutual labels:  laravel, helper
Laravel Boilerplate
Laravel Boilerplate / Starter Kit with Gentelella Admin Theme
Stars: ✭ 704 (+156%)
Mutual labels:  laravel, bootstrap
Laravel Bootstrap Components
Bootstrap components as Laravel components
Stars: ✭ 190 (-30.91%)
Mutual labels:  laravel, bootstrap
Laravel Bootstrap 4 Forms
Bootstrap 4 forms for Laravel 5/6/7/8
Stars: ✭ 181 (-34.18%)
Mutual labels:  laravel, bootstrap
Laravel Settings
Simple Settings package for a laravel application
Stars: ✭ 45 (-83.64%)
Mutual labels:  laravel, bootstrap
Bootstrap Form
Bootstrap 3 form builder for Laravel
Stars: ✭ 225 (-18.18%)
Mutual labels:  laravel, bootstrap
Freelancers Market
Laravel Project to help freelance websites clients and freelancers to find each other.
Stars: ✭ 39 (-85.82%)
Mutual labels:  laravel, bootstrap
Ecommerce Laravel Bootstrap
Responsive, Multi-Vendor, MultiLanguage Online Store Platform (shopping cart solution)
Stars: ✭ 99 (-64%)
Mutual labels:  laravel, bootstrap
Laravel Bootstrap Table List
Bootstrap table list generator for Laravel.
Stars: ✭ 16 (-94.18%)
Mutual labels:  laravel, bootstrap
Lqycms
基于laravel框架的企业级开源cms管理系统,开源php商城源码,B2C微商城系统,企业建站cms。
Stars: ✭ 142 (-48.36%)
Mutual labels:  laravel, bootstrap
Laravel Vue Pagination
A Vue.js pagination component for Laravel paginators that works with Bootstrap
Stars: ✭ 541 (+96.73%)
Mutual labels:  laravel, bootstrap
Laracms
LaraCMS 是在学习 laravel ( web 开发实战进阶 + 实战构架 API 服务器) 过程中产生的一个业余作品,试图通过简单的方式,快速构建一套基本的企业站同时保留很灵活的扩展能力和优雅的代码方式,当然这些都得益Laravel的优秀设计。同时LaraCMS 也是一个学习Laravel 不错的参考示例。
Stars: ✭ 588 (+113.82%)
Mutual labels:  laravel, bootstrap
Ignition Go
Bootstrap4 /Codeigniter 3 Modular (HMVC) App Building Framework - to build enterprise class web applications... Versions: CodeIgniter 3.1.9 AdminLTE 3.4 Bootstrap 4.5.0
Stars: ✭ 166 (-39.64%)
Mutual labels:  laravel, bootstrap
Cms
Multilingual PHP CMS built with Laravel and bootstrap
Stars: ✭ 2,342 (+751.64%)
Mutual labels:  laravel, bootstrap

Ekko

Framework agnostic PHP package for marking navigation items active.

Become a Patron

New features in v3

  • Framework agnostic
  • Can be modified for any custom application
  • Currently supported frameworks: Laravel (PRs are welcome!)
  • Global helper functions disabled by default
  • Supports default output value
  • Backward compatible with v1 & v2
  • Fully tested using table driven testing (data providers in PHPUnit)

Installation

From the command line:

composer require laravelista/ekko

By default Ekko is initialized with these sensible defaults:

  • the default output value is active.
  • it uses GenericUrlProvider ($_SERVER['REQUEST_URI']).
  • global helper functions are disabled.

Laravel

The only dependency for this package is PHP 7.2+, meaning that you can possibly install it on any Laravel version that supports PHP 7.2. The service provider is always going to follow the latest Laravel release and try to be as backward compatible as possible.

Laravel 5.5+ will use the auto-discovery function to register the ServiceProvider and the Facade.

If using 5.4 (or if you are not using auto-discovery) you will need to include the service provider and facade in config/app.php:

'providers' => [
    ...,
    Laravelista\Ekko\Frameworks\Laravel\ServiceProvider::class
];

And add a facade alias to the same file at the bottom:

'aliases' => [
    ...,
    'Ekko' => Laravelista\Ekko\Frameworks\Laravel\Facade::class
];

Overview

To mark a menu item active in Bootstrap, you need to add a active CSS class to the <li> tag:

<ul class="nav navbar-nav">
    <li class="active"><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

You could do it manually with Laravel, but you will end up with a sausage:

<ul class="nav navbar-nav">
    <li class="@if(URL::current() == URL::to('/')) active @endif"><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

With Ekko your code could look like this:

<ul class="nav navbar-nav">
    <li class="{{ Ekko::isActive('/') }}"><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

or like this:

<ul class="nav navbar-nav">
    <li class="{{ Ekko::isActiveRoute('home') }}"><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

or this:

<ul class="nav navbar-nav">
    <li class="{{ $ekko->isActive('/') }}"><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

Default output value

What if you are not using Bootstrap, but some other framework or a custom design? Instead of returning active CSS class, you can make Ekko return anything you want.

<ul class="nav navbar-nav">
    <li class="{{ Ekko::isActive('/', 'highlight') }}"><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

You can alse set the default output value if you don't want to type it everytime:

$ekko = new Ekko;
$ekko->setDefaultValue('highlight');
return $ekko->isActive('/');

or in Laravel you can set the default output value in the config config/ekko.php file:

<?php

return [
    'default_output' => 'highlight'
];

To publish the config for Ekko use this in Laravel:

php artisan vendor:publish --provider="Laravelista\Ekko\Frameworks\Laravel\ServiceProvider"

Using boolean true or false is convenient if you need to display some content depending on which page you are in your layout view:

@if(Ekko::isActive('/about', true))
    <p>Something that is only visible on the `about` page.</p>
@endif

Global helper functions

Global helper functions as displayed above are disabled by default. To enable them use Ekko::enableGlobalHelpers(); or $ekko->enableGlobalHelpers().

In Laravel add this code to your app/Providers/AppServiceProvider.php file in register method:

\Ekko::enableGlobalHelpers();

Usage

When used outside a framework, this package has only one main method of interest called isActive. The function accepts an input which can be a string or an array of strings, and an output which can be anything. The default output is active.

<li class="{{ $ekko->isActive('/') }}"><a href="/">Home</a></li>
<li class="{{ $ekko->isActive(['/', '/home]) }}"><a href="/">Home</a></li>
<li class="{{ $ekko->isActive(['/', '/home, '*home*']) }}"><a href="/">Home</a></li>
<li class="{{ $ekko->isActive('/home*') }}"><a href="/">Home</a></li>
<li class="{{ $ekko->isActive('/home*feature=slideshow*') }}"><a href="/">Home</a></li>
<li class="{{ $ekko->isActive('/index.php?page=*') }}"><a href="/">Home</a></li>

It supports strings, arrays, wildcards and query parameters.

Laravel usage

Use the facade Ekko::, resolve(Ekko::class) or app(Ekko::class) to obtain the Laravel bootstraped instance.

Laravel comes with few special methods for named routes and other helper methods. Also, there is a lot of backward compatibility here for v1 of this package.

Methods

Ekko::isActive($input, $output = null) This calls the main Ekko method isActive. Described above.

Ekko::isActiveRoute($input, $output = null) For named routes. Supports arrays and wildcards.

Ekko::areActiveRoutes(array $input, $output = null) For arrays of named routes. Supports wildcards. Backward compatibility. Use isActiveRoute and pass it the same array.

Ekko::isActiveURL($input, $output = null) The same as Ekko::isActive. Backward compatibility. Use Ekko::isActive and pass it the same input.

Ekko::areActiveURLs(array $input, $output = null) The same as Ekko::isActiveURL, but accepts only the array of Urls. Backward compatibility. Use Ekko::isActive and pass it the same array.

Ekko::isActiveMatch($input, $output = null) The same as Ekko::isActive. This method encloses the input with wildcard *. Supports string, array and wildcards as input. Backward compatibility. Use Ekko::isActive and pass it the same input, but with wildcard * at the desired place.

Ekko::areActiveMatches(array $input, $output = null) The same as Ekko::isActiveMatch, but accepts only the array of strings. Backward compatibility. Use Ekko::isActive and pass it the same array.

Credits

Many thanks to:

Sponsors & Backers

I would like to extend my thanks to the following sponsors & backers for funding my open-source journey. If you are interested in becoming a sponsor or backer, please visit the Backers page.

Contributing

Thank you for considering contributing to Ekko! The contribution guide can be found Here.

Code of Conduct

In order to ensure that the open-source community is welcoming to all, please review and abide by the Code of Conduct.

License

Ekko is open-source software licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].