Logo

Html->script()

ops...

Description

Include a script file(s), contained either locally or as a remote URL. By default, script tags are added to the document inline. If you override this by setting $options['block'] to true, the script tags will instead be added to the script block which you can print elsewhere in the document. If you wish to override which block name is used, you can do so by setting $options['block']. $options['once'] controls whether or not you want to include this script once per request or more than once. This defaults to true. You can use $options to set additional properties to the generated script tag. If an array of script tags is used, the attributes will be applied to all of the generated script tags. This method of JavaScript file inclusion assumes that the JavaScript file specified resides inside the webroot/js directory:

Usage: script(mixed $url, mixed $options) echo $this->Html->script('scripts'); echo $this->Html->script('script', ['defer' => true, 'type' => 'module']); Output: <script src="/js/scripts.js"></script> <script src="/js/script.js"></script>