registerJs not working


For some reason I can’t get registerJs to work. I put this very simple code in a view

$this->registerJs("alert('test');", View::POS_END, 'myTest');

and nothing happens. I view the source of the page and the script is not there. I’ve tried it in a few views as well as the layout and nothing works. I’ve got “use \yii\web\View” in the top of the page. Any suggestions?

I didn’t realize that I needed to register the asset package as described here. I also needed to add the required tags (e.g. <?php $this->endBody() ?>) in the layout file.

I guess I should have studied the documentation better first. Everything works now.