Skip to content

Kirby 3.7.5


Creates a script tag to load a javascript file

js(string|array $url, string|array $options = null): string|null


Name Type Default
$url * string|array
$options string|array null

Return type



Creating a single script tag

<?= js('assets/js/site.js') ?>

Creating multiple script tags

<?= js([
]) ?>

Autoloading template specific script files

<?= js('@auto') ?>

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


If you want the JS files to be loaded asynchronously (if supported by the browser), you can set a second parameter to true:

<?= js('assets/js/site.js', true) ?>

This also works with an array of paths:

<?= js([
], true) ?>

Other attributes

You can also pass an array of completely custom attributes like the defer attribute:

<?= js('assets/js/site.js', ['async' => true, 'defer' => true, 'data-something' => 'my-value']) ?>