Last active
December 28, 2018 06:48
-
-
Save mitrallex/f6008dd8376c704d6ec5ce92b48eda6c to your computer and use it in GitHub Desktop.
Just in case-active submenu items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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