At the moment there is a main asset of the application that is connected in the main template. I also have a module for which I have my asset, I connect it in the necessary views of the module. However, the main application styles overlap the module styles, that is, I see such a picture

<link href="/assets/1fd9cc17/css/style.css" rel="stylesheet"> <link href="/css/slick-theme.css" rel="stylesheet"> <link href="/css/slick.css" rel="stylesheet"> 

Is it possible to somehow redefine the connection sequence?

  • you need to add 'ClientScript :: reset ()' to the 'preint' module method to skip the base scripts in the module - Kirill
  • Thanks for the answer, but can you give more details on how to do this? - Anatoly

1 answer 1

The module should have an assets folder where module.css, module.js are stored.

 class SomeModule extends CWebModule { /** * @var string the path to this modules published asset directory */ protected $assetsUrl; public function preinit() { // Reset the front-end's client script because we don't want // both front-end styles being applied in this module. Yii::app()->clientScript->reset(); } public function init() { $this->registerCoreCss(); $this->registerCoreJs(); } /** * Registers the published module CSS */ protected function registerCoreCss() { Yii::app()->clientScript->registerCssFile($this->getAssetsUrl('/module.css')); } /** * Registers the published module JS */ protected function registerCoreJs() { Yii::app()->clientScript->registerScriptFile($this->getAssetsUrl('/module.js'), CClientScript::POS_BEGIN); } /** * Publishes and returns the URL to the assets folder. * @return string the URL */ protected function getAssetsUrl($path = '', $home = false) { $assetsPath = ($home) ? Yii::getPathOfAlias('webroot') : Yii::getPathOfAlias('some.assets'); $assetsUrl = Yii::app()->assetManager->publish($assetsPath . $path, false, -1, false); return $assetsUrl; } }