phpyiiyii-modules

how and where to include js and css for modules?


I have modules for category:

+modules/
 +category/
    +assets/
      +css/
      +js/
      +images/
    +components/
    +controllers/
    +models/
    +views/
    -CategoryModule.php

What is the best way to includes the css and jss to all views?


Solution

  • Publish and register in CategoryModule init method - this will make available your css and js in category module.
    Something like this:

    public function  init() {
        $path = $this->assetManager->publish(Yii::getPathOfAlias('application.modules.category.assets'));
        $this->clientScript->registerCssFile($path . '/css/some-css.css', 'screen, projection');
        $this->clientScript->registerScriptFile($path . '/js/some-js.js');
    }