L
L
lilwings2020-12-31 08:03:24
Yii
lilwings, 2020-12-31 08:03:24

How to mark active link in yii2?

How can I add a class to the active link?

<div class="sidebar__nav-list">
    <a href="<?= URL::toRoute('dashboard/dashboard') ?>" class="sidebar__nav-item">
        <img src="/admin/images/sidebar/dashboard.png" class="sidebar__icon-item">
    </a>

    <a href="<?= URL::toRoute('info/info') ?>" class="sidebar__nav-item">
        <img src="/admin/images/sidebar/info.png" class="sidebar__icon-item">
    </a>

    <a href="<?= URL::toRoute('news/news') ?>" class="sidebar__nav-item">
        <img src="/admin/images/sidebar/news.png" class="sidebar__icon-item">
    </a>
</div>

Two questions:
1) How to add an active class to the controller? (i.e. If the site controller is a link that refers to its action, no matter which one the active class should receive)
2) How to add a class by controller and action? (i.e. If the controller site and action - news - then add a class only to the link that leads to site / news)
No idea how this can be done :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BATPYIIIKOB, 2020-12-31
@BATPYIIIKOB

Everything is mixed up.. horses, people...
Class Do you mean CSS class? What do you mean by active class? You can assign any template to any action and pass any data to it, on the basis of which you can implement the substitution of the CSS class in the desired item.
I understand - your task is to make a menu with active elements ??

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question