Answer the question
In order to leave comments, you need to log in
Yii2. How to remove classes generated by Yii in widgets?
I am using the NavBar widget. Code like this:
<?php NavBar::begin([
'renderInnerContainer' => false,
'options' => [
'renderInnerContainer' => false,
'tag' => 'div',
'class' => 'row',
],
]); ?>
...
<?php NavBar::end(); ?>
<div id="w0" class="row navbar" role="navigation">
...
</div>
Answer the question
In order to leave comments, you need to log in
Redefine the class with your own and business.
class NavBar extends \yii\bootstrap\NavBar
{
public function init()
{
parent::init();
Html::removeCssClass($this->options, 'navbar');
}
}
I really don't recommend doing that. Six months later, you will forget that something has changed there, and when you update the widget, everything will be overwritten, if you really want to delete the class, do it through jQuery.$('#w0').removeClass('navbar');
In general, I didn’t come up with anything better than getting into the source code of the widget and commenting out the line adding this class there.
The question is valid. I would like a more elegant solution.
// Update
It's better not to comment the line, but rewrite it like this:
if (!isset($this->options['class'])){
Html::addCssClass($this->options, 'navbar');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question