sahibalejandro / laravel-active-menu by sahibalejandro

Blade directives to manage menu states in a clean an easy way.
122
1
2
Package Data
Maintainer Username: sahibalejandro
Maintainer Contact: sahib@sahib.io (Sahib J. Leo)
Package Create Date: 2016-08-09
Package Last Update: 2016-09-07
Language: PHP
License: MIT
Last Refreshed: 2024-05-03 15:12:41
Package Statistics
Total Downloads: 122
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Active Menu

Build Status Latest Stable Version Total Downloads License

Blade directives for Laravel 5.1+ to manage menu states in a clean an easy way.

Install

composer require sahibalejandro/laravel-active-menu

Usage

Call @activate(...) to specify the activated menu:

@activate('security_settings')

Now call @active(...) directive to know if a specified menu is active:

<ul>
    <li>
        <a href="/settings">Settings</a>
        <ul class="dropdown">
            <li class="@active('security_settings')">
                <a href="/settings/security">Security</a>
            </li>
        </ul>
    </li>
</ul>

This directive will print the string active if the given menu is activated. The example above will result on the following HTML:

<ul>
    <li>
        <a href="/settings">Settings</a>
        <ul class="dropdown">
            <li class="active">
                <a href="/settings/security">Security</a>
            </li>
        </ul>
    </li>
</ul>

Now just add a li.active a { ... } styles to your CSS and you're ready.

Using dot-notation

Use dot-notation to activate the menu cascade up, for example, using this directive:

@activate('settings.security')

This will activate settings and settings.security, so the following directives will print the string active:

@active('settings')
@active('settings.security')

Change the class name

You can change the class name passing it as a second parameter:

@active('user.account', 'link-active')

But I really recomend you stick to the convention and use the default value.