A
A
Anton2016-09-14 03:37:14
Yii
Anton, 2016-09-14 03:37:14

How to override widget styles?

Hello, there is a widget with its own styles, how can I override its styles with my css file connected to the page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlikDex, 2016-09-14
@AlikDex

You can redefine the component in the config, it's done like this:

'assetManager' => [
        'bundles' => [
            'some\namespace\SomeAsset' => [
                'sourcePath' => '@web/myassets/folder',   // redeclare default folder
                'css' => [
                    'my_widget_style.css',
                    'other_style.css',
                ],
                'js' => [
                ],
                'depends' => [
                ],
            ],
        ],
    ],

D
Dmitry, 2016-09-14
@slo_nik

Good morning.
Everything is simple.
Create an assets directory in the widget directory, add css files there and create your WidgetAssets (inherited from AssetBundle) where you write resource files.
The structure is as follows:
The contents of the SwitchThemesAsset.php file

class SwitchThemesAsset extends AssetBundle
{
  public $css = [
       'css/switchthemes.css'
  ];

  public function init()
  {
    $this->sourcePath = __DIR__.'/assets';
    parent::init();
  }
}

The name of the widget, as you can guess, should be yours)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question