js()
Creates a script tag to load a javascript file
Parameters
Name | Type | Default |
---|---|---|
$url * | string |array |
– |
$options | string |array |
null |
Return type
string
|null
Example
Creating a single script tag
Creating multiple script tags
Autoloading template specific script files
Template specific JS files must be located in /assets/js/templates
and named like the template.
Template | JS file |
---|---|
/site/templates/project.php | /assets/js/templates/project.js |
/site/templates/home.php | /assets/js/templates/home.js |
/site/templates/blog.php | /assets/js/templates/blog.js |
Async
If you want the JS files to be loaded asynchronously (if supported by the browser), you can set a second parameter to true
:
This also works with an array of paths:
Other attributes
You can also pass an array of completely custom attributes like the defer
attribute: