How to include java script CSS file in Yii Framework


(Hemendra Singh) #1

I want to create a page on my site that has a little Javascript application running, so I want to include .js and .css files in a specific view.


(Miodrag Stojanović) #2

view => site/about.php

// 1
$JS = <<<JS
    console.log("hello from yii");
JS;
$this->registerJS($JS, \yii\web\VIEW::POS_END);
// 2
$this->registerJsFile('path/to/your/jsfile');

// css
$this->registerCssFile('path/to/your/cssfile', [
    'depends' => [\yii\web\JqueryAsset::class]
]);

(Softark) #3

Please check the following section of the guide.

Guide > Displaying Data > Working with Client Scripts