{"id":20914819,"url":"https://github.com/laravelista/ekko","last_synced_at":"2025-05-16T18:08:19.618Z","repository":{"id":32488395,"uuid":"36068872","full_name":"laravelista/Ekko","owner":"laravelista","description":"Framework agnostic PHP package for marking navigation items active.","archived":false,"fork":false,"pushed_at":"2021-03-25T11:31:15.000Z","size":254,"stargazers_count":279,"open_issues_count":0,"forks_count":28,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-18T17:45:03.294Z","etag":null,"topics":["active","bootstrap","helper","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laravelista.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"laravelista"}},"created_at":"2015-05-22T11:31:28.000Z","updated_at":"2024-05-02T16:43:17.000Z","dependencies_parsed_at":"2022-07-30T19:48:08.710Z","dependency_job_id":null,"html_url":"https://github.com/laravelista/Ekko","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravelista%2FEkko","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravelista%2FEkko/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravelista%2FEkko/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravelista%2FEkko/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laravelista","download_url":"https://codeload.github.com/laravelista/Ekko/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248600945,"owners_count":21131578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["active","bootstrap","helper","laravel","php"],"created_at":"2024-11-18T16:11:10.122Z","updated_at":"2025-04-12T16:46:47.379Z","avatar_url":"https://github.com/laravelista.png","language":"PHP","funding_links":["https://patreon.com/laravelista","https://www.patreon.com/laravelista"],"categories":[],"sub_categories":[],"readme":"# Ekko\n\nFramework agnostic PHP package for marking navigation items active.\n\n[![Become a Patron](https://img.shields.io/badge/Become%20a-Patron-f96854.svg?style=for-the-badge)](https://www.patreon.com/laravelista)\n\n## Features\n\n- Framework agnostic.\n- Can be modified for any custom application and UI.\n- Currently supported frameworks: Laravel (PRs are welcome!).\n- Global helper functions disabled by default.\n- Supports default output value.\n- Backward compatible.\n- Fully tested using table driven testing (data providers in PHPUnit).\n\n## Installation\n\nFrom the command line:\n\n```bash\ncomposer require laravelista/ekko\n```\n\nBy default Ekko is initialized with these sensible defaults:\n\n- the default output value is `active`.\n- it uses GenericUrlProvider (`$_SERVER['REQUEST_URI']`).\n- global helper functions are disabled.\n\n### Laravel\n\nThe only dependency for this package is PHP ^8.0, meaning that you can possibly install it on any Laravel version that supports PHP 8 (I think that for now this is only Laravel 8). The service provider is always going to follow the latest Laravel release and try to be as backward compatible as possible.\n\nLaravel 8 will use the auto-discovery function to register the ServiceProvider and the Facade.\n\nIf you are not using auto-discovery, you will need to include the service provider and facade in `config/app.php`:\n\n```\n'providers' =\u003e [\n    ...,\n    Laravelista\\Ekko\\Frameworks\\Laravel\\ServiceProvider::class\n];\n```\n\nAnd add a facade alias to the same file at the bottom:\n\n```\n'aliases' =\u003e [\n    ...,\n    'Ekko' =\u003e Laravelista\\Ekko\\Frameworks\\Laravel\\Facade::class\n];\n```\n\n## Overview\n\nTo mark a menu item active in [Bootstrap](http://getbootstrap.com/components/#navbar), you need to add a `active` CSS class to the `\u003cli\u003e` tag:\n\n```html\n\u003cul class=\"nav navbar-nav\"\u003e\n    \u003cli class=\"active\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nYou could do it manually with Laravel, but you will end up with a sausage:\n\n```html\n\u003cul class=\"nav navbar-nav\"\u003e\n    \u003cli class=\"@if(URL::current() == URL::to('/')) active @endif\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nWith Ekko your code could look like this:\n\n```html\n\u003cul class=\"nav navbar-nav\"\u003e\n    \u003cli class=\"{{ Ekko::isActive('/') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nor like this:\n\n```html\n\u003cul class=\"nav navbar-nav\"\u003e\n    \u003cli class=\"{{ Ekko::isActiveRoute('home') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nor this:\n\n```html\n\u003cul class=\"nav navbar-nav\"\u003e\n    \u003cli class=\"{{ $ekko-\u003eisActive('/') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n### Default output value\n\nWhat 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.\n\n```html\n\u003cul class=\"nav navbar-nav\"\u003e\n    \u003cli class=\"{{ Ekko::isActive('/', 'highlight') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nYou can alse set the **default output value** if you don't want to type it everytime:\n\n```php\n$ekko = new Ekko;\n$ekko-\u003esetDefaultValue('highlight');\nreturn $ekko-\u003eisActive('/');\n```\n\nor in Laravel you can set the default output value in the config `config/ekko.php` file:\n\n```php\n\u003c?php\n\nreturn [\n    'default_output' =\u003e 'highlight'\n];\n```\n\nTo publish the config for Ekko use this in Laravel:\n\n```\nphp artisan vendor:publish --provider=\"Laravelista\\Ekko\\Frameworks\\Laravel\\ServiceProvider\"\n```\n\nUsing boolean `true` or `false` is convenient if you need to display some content depending on which page you are in your layout view:\n\n```html\n@if(Ekko::isActive('/about', true))\n    \u003cp\u003eSomething that is only visible on the `about` page.\u003c/p\u003e\n@endif\n```\n\n### Global helper functions\n\n**Global helper functions** are disabled by default. To enable them use `Ekko::enableGlobalHelpers();` or `$ekko-\u003eenableGlobalHelpers()`.\n\nIn Laravel add this code to your `app/Providers/AppServiceProvider.php` file in `register` method:\n\n```\n\\Ekko::enableGlobalHelpers();\n```\n\n## Usage\n\nWhen 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`.\n\n```\n\u003cli class=\"{{ $ekko-\u003eisActive('/') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n\u003cli class=\"{{ $ekko-\u003eisActive(['/', '/home]) }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n\u003cli class=\"{{ $ekko-\u003eisActive(['/', '/home, '*home*']) }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n\u003cli class=\"{{ $ekko-\u003eisActive('/home*') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n\u003cli class=\"{{ $ekko-\u003eisActive('/home*feature=slideshow*') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n\u003cli class=\"{{ $ekko-\u003eisActive('/index.php?page=*') }}\"\u003e\u003ca href=\"/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n```\n\nIt supports strings, arrays, wildcards and query parameters.\n\n### Laravel usage\n\nUse the facade `Ekko::`, `resolve(Ekko::class)` or `app(Ekko::class)` to obtain the Laravel bootstraped instance.\n\nLaravel 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.\n\n#### Methods\n\n`Ekko::isActive($input, $output = null)`\nThis calls the main Ekko method isActive. Described above.\n\n`Ekko::isActiveRoute($input, $output = null)`\nFor named routes. Supports arrays and wildcards.\n\n`Ekko::areActiveRoutes(array $input, $output = null)`\nFor arrays of named routes. Supports wildcards.\n**Backward compatibility.** Use `isActiveRoute` and pass it the same array.\n\n`Ekko::isActiveURL($input, $output = null)`\nThe same as `Ekko::isActive`.\n**Backward compatibility.** Use `Ekko::isActive` and pass it the same input.\n\n`Ekko::areActiveURLs(array $input, $output = null)`\nThe same as `Ekko::isActiveURL`, but accepts only the array of Urls.\n**Backward compatibility.** Use `Ekko::isActive` and pass it the same array.\n\n`Ekko::isActiveMatch($input, $output = null)`\nThe same as `Ekko::isActive`. This method encloses the input with wildcard `*`. Supports string, array and wildcards as input.\n**Backward compatibility.** Use `Ekko::isActive` and pass it the same input, but with wildcard `*` at the desired place.\n\n`Ekko::areActiveMatches(array $input, $output = null)`\nThe same as `Ekko::isActiveMatch`, but accepts only the array of strings.\n**Backward compatibility.** Use `Ekko::isActive` and pass it the same array.\n\n## Development\n\n```bash\n# Install dependencies\ncomposer install\n\n# Run tests\nvendor/bin/phpunit\n\n# Run Psalm\nvendor/bin/psalm\n\n# Format code (php-cs-fixer)\nvendor/bin/php-cs-fixer\n```\n\n## Credits\n\nMany thanks to:\n\n- [@judgej](https://github.com/judgej) for route wildcards.\n- [@Jono20201](https://github.com/Jono20201) for helper functions.\n- [@JasonMillward](https://github.com/JasonMillward) for improving wildcards in nested route names.\n- [@it-can](https://github.com/it-can) for Laravel 5.5+ auto-discovery.\n- [@foo99](https://github.com/foo99) for snake_case function names.\n- [@Turboveja](https://github.com/Turboveja) for are_active_matches function.\n\n## Sponsors \u0026 Backers\n\nI would like to extend my thanks to the following sponsors \u0026 backers for funding my open-source journey. If you are interested in becoming a sponsor or backer, please visit the [Backers page](https://mariobasic.com/backers).\n\n## Contributing\n\nThank you for considering contributing to Ekko! The contribution guide can be found [Here](https://mariobasic.com/contributing).\n\n## Code of Conduct\n\nIn order to ensure that the open-source community is welcoming to all, please review and abide by the [Code of Conduct](https://mariobasic.com/code-of-conduct).\n\n## License\n\nEkko is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravelista%2Fekko","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaravelista%2Fekko","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravelista%2Fekko/lists"}