E
E
Evgeny Khakhalkin2017-03-29 17:59:07
Yii
Evgeny Khakhalkin, 2017-03-29 17:59:07

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

1 answer(s)
A
alex stephen, 2017-03-29
@berezuev

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 question

Ask a Question

731 491 924 answers to any question