Skip to content

Instantly share code, notes, and snippets.

@amberlex78
Created August 9, 2020 07:04
Show Gist options
  • Select an option

  • Save amberlex78/cc21d7b0229bbd54afd25d1cb3e7ebd3 to your computer and use it in GitHub Desktop.

Select an option

Save amberlex78/cc21d7b0229bbd54afd25d1cb3e7ebd3 to your computer and use it in GitHub Desktop.
Highlighting multi-level menu items

Highlighting multi-level menu items

In a multi-level menu, you usually have to highlight the selected menu item and its parent element. This can be done based on the parent route.

<ul>
  <li>
    <a href="{{ route('admin.posts.index') }}"
       class="{{ Str::is('admin.posts.*', Route::currentRouteName()) ? 'is-active' : '' }}">
      Manage Posts
    </a>
    <ul>
      <li class="{{ Route::currentRouteName() === 'admin.posts.index' ? 'is-active' : '' }}">
        <a href="{{ route('admin.posts.index') }}">All Posts</a>
      </li>
      <li class="{{ Route::currentRouteName() === 'admin.posts.create' ? 'is-active' : '' }}">
        <a href="{{ route('admin.posts.create') }}">Create Post</a>
      </li>
      <li class="{{ Route::currentRouteName() === 'admin.posts.settings' ? 'is-active' : '' }}">
        <a href="{{ route('admin.posts.settings') }}">Settings</a>
      </li>
    </ul>
  </li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment