A
A
Alexander Ivanov2015-06-15 23:20:39
Yii
Alexander Ivanov, 2015-06-15 23:20:39

How to customize dropdown menu in Yii2?

Below is my menu implementation in yii2:

echo Nav::widget([
                'options' => ['id' => 'topnav','class' => 'navbar-default center-block text-center'],//.navbar-nav
                'items' => [
                    ['label' => 'О нас', 'url' => ['/site/about']],
                    ['label' => 'История', 'url' => ['/site/history']],
                    ['label' => 'Деятельность', 'url' => ['/site/activities'],
          'options' => ['id' => 'down_menu'],			
          'items' => [
                      ['label' => 'Наши собаки', 'url' => ['/site/history'],'options' => ['id' => 'down_history']],
                      ['label' => 'Наши волонтёры', 'url' => ['/site/event'],'options' => ['id' => 'wn_history']],
          ['label' => 'Реабилитация', 'url' => ['/activities/reabilitation'],'options' => ['id' => 'n_history']],
                      ['label' => 'Спонсорам и партнёрам', 'url' => ['/activities/sponsor']],]],
                    ['label' => 'Мероприятия', 'url' => ['/site/event']],
                    ['label' => 'СМИ о нас', 'url' => ['/site/smi']],
                ],
            ]);

The question is rather how deep I can customize the menu.
The menu I want to implement looks like drop down menus for price and service items.
http://k7g.rf/couch/
where it is implemented through an additional block in the list:
<ul>
<li>
   <div id="блок на всю ширину">
  <ul>
     <li>
     <li>
  <.ul>
   </div>
</li>
</ul>

Is there any way I can insert drop down menu items into a div, right in the yii code?
So I tried, but apparently the widget cannot be separated:
['label' => 'Деятельность', 'url' => ['/site/activities'],
            ?><div id="hjk"><?php
            'options' => ['id' => 'down_menu'],			
            'items' => [
              ['label' => 'Наши собаки', 'url' => ['/site/history'],'options' => ['id' => 'down_history']],
              ['label' => 'Наши волонтёры', 'url' => ['/site/event'],'options' => ['id' => 'wn_history']],
              ['label' => 'Реабилитация', 'url' => ['/activities/reabilitation'],'options' => ['id' => 'n_history']],
              ['label' => 'Спонсорам и партнёрам', 'url' => ['/activities/sponsor']],]],
            ?></div><?php
                    ['label' => 'Мероприятия', 'url' => ['/site/event']],

I would also like advice on how to set the id for the drop-down ul:
<ul id="w0" class="dropdown-menu"><li id="down_history"><a href="/index.php?r=site%2Fhistory" tabindex="-1">Наши собаки</a></li>
<li id="wn_history" class="active"><a href="/index.php?r=site%2Fevent" tabindex="-1">Наши волонтёры</a></li>
...

By default, it is called w0, then where do you need to write options to set the value for it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-06-16
@vyachin

1. Yes you can, through items

['label' => 'Наши собаки','options' => ['id' => 'down_history'], 'items'=>[
    ['label' => 'Наши волонтёры', 'url' => ['/site/event'],'options' => ['id' => 'wn_history']],
]],

2. id can be assigned via options https://github.com/yiisoft/yii2-bootstrap/blob/mas... in step 1. just as it is assigned

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question