Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to register a js script in yii?


Asked by Braelyn Nolan on Dec 15, 2021 FAQ



This widget help you register JS script in Yii just as you write script block directly into HTML! to the require section of your composer.json file. In your view file, wrap your JS script with <script> tag, and wrap all the things with this widget.
Additionally,
Further, if, for whatever reason, you register the same JavaScript file more than once, Yii will still only create a single SCRIPT tag for that file. By default, Yii will link the registered script in the HTML HEAD.
Consequently, While it is possible to put it in many places, in the Yii framework, its place in the “css” or “js” folders which are already present in your application by default. If your file is a CSS file, it goes here:
Besides,
When working with the yii\web\View object you can dynamically register frontend scripts. There are two dedicated methods for this: Inline scripts are useful for configuration, dynamically generated code and small snippets created by reusable frontend code contained in widgets .
Also Know,
When you click Sign Up, you'll see the confirmation notification. This tells us an email has been sent that we need to click on to verify our registration. Notice the login state maintained by Yii2 and the Yii2-User component—it's displayed in the navigation bar above.