On my website on Yii2 at the top there is a menu that is implemented by the NavBar component.

NavBar::begin([ 'brandLabel' => Yii::$app->name, 'brandUrl' => Yii::$app->homeUrl, 'options' => [ 'class' => 'navbar-inverse navbar-fixed-top logotype', ], ]); 

The 'class' key defines the classes for the nav tag. Here is the layout.

  <nav id="w0" class="navbar-inverse navbar-fixed-top logotype navbar"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#w0-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button><a class="navbar-brand" href="/index.php"></a> </div> <div id="w0-collapse" class="collapse navbar-collapse"> <ul id="w1" class="navbar-nav navbar-right nav"><li><a href="/index.php?r=site%2Fregister">Регистрация</a></li> <li><a href="/index.php?r=site%2Flogin">Вход</a></li> </ul></div></div> </nav> 

Inside there are divs, I want to change this, add more. Where are these files in yii2? Search only finds .css classes only. I understand that this is somewhere in the logic of the NavBar component. How to edit it?

  • you don’t need to edit it as they are in the vendor folder, when you upgrade the composer, everything will fly off, you need to override the NavBar class - madfan41k

1 answer 1

You can add any content between the opening and closing methods of the widget.

 <?=NavBar::begin();?> <div>Любой контент</div> <?=NavBar::end();?>