Answer the question
In order to leave comments, you need to log in
How to replace link with text if page is active YII2?
Good day, fellow developers!
I want to implement the following functionality on the site: if the user is on the page, then the link in the menu becomes text, i.e. you can no longer click on it.
Of course, I can create a condition for comparing the url and the menu link for each link. And already based on this condition, give the menu item as a link or text.
It seems to me that this is not quite the best option. Maybe in YII2 there is some function or rule in urlManager that simply implements such functionality?
Thank you!
Answer the question
In order to leave comments, you need to log in
Afaik The standard menu widget does this by default.
UPD:
here's how it's done:
$menuItems = [
['label' => 'Home', 'url' => ['/'], 'active' => $this->context->route == 'site/index'],
['label' => 'About', 'url' => ['/about'], 'active' => $this->context->route == 'site/about'],
['label' => 'Projects', 'url' => ['/projects'], 'active' => $this->context->route == 'site/projects'],
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question