How to include java script CSS file in Yii Framework

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.

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]
]);
1 Like

Please check the following section of the guide.

Guide > Displaying Data > Working with Client Scripts

1 Like