Skip to content

Instantly share code, notes, and snippets.

@mitrallex
Last active December 28, 2018 06:48
Show Gist options
  • Save mitrallex/f6008dd8376c704d6ec5ce92b48eda6c to your computer and use it in GitHub Desktop.
Save mitrallex/f6008dd8376c704d6ec5ce92b48eda6c to your computer and use it in GitHub Desktop.
Just in case-active submenu items
<?php
/**
*
* Set active css class if the specific URI is current URI by fragments.
*
* @param string $path A specific URI
* @param string $class_name Css class name, optional
* @return string Css class name if it's current URI,
* otherwise - empty string
*/
function setActiveBySegments(string $path, string $class_name = "is-active")
{
$request_path = implode('/', Request::segments());
return $request_path === $path ? $class_name : "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment