O
O
oe24y2016-02-23 08:44:11
Yii
oe24y, 2016-02-23 08:44:11

How to highlight menu items in Yii2 depending on the open page?

Here's how on the Toaster, for example:
56cbf1827e4ff.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Voronkov, 2016-02-23
@DmitryVoronkov

echo Nav::widget([
    'activateItems' => true,
    'items' => [
        [
            'label' => 'Home',
            'url' => ['site/index'],
            'linkOptions' => [...],
        ],
        [
            'label' => 'Dropdown',
            'items' => [
                 ['label' => 'Level 1 - Dropdown A', 'url' => '#'],
                 '<li class="divider"></li>',
                 '<li class="dropdown-header">Dropdown Header</li>',
                 ['label' => 'Level 1 - Dropdown B', 'url' => '#'],
            ],
        ],
        [
            'label' => 'Login',
            'url' => ['site/login'],
            'visible' => Yii::$app->user->isGuest
        ],
    ],
    'options' => ['class' =>'nav-pills'], // set this to nav-tab to get tab-styled navigation
]);

Doc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question