lithium\template\helper\Html::script()
Returns a JavaScript include tag (<script />
element). If the filename is prefixed with
'/'
, the path will be relative to the base path of your application. Otherwise, the path
will be relative to your JavaScript path, usually webroot/js
.
Parameters
-
mixed
$path
String The name of a JavaScript file, or an array of names.
-
array
$options
Available options are:
'inline'
boolean: Whether or not the<script />
element should be output inline. When set to false, thescripts()
handler prints out the script, and other specified scripts to be included in the layout. Defaults totrue
. This is useful when page-specific scripts are created inline in the page, and you'd like to place them in the<head />
along with your other scripts.- any other options specified are rendered as HTML attributes of the element.
Returns
stringFilter
This method can be filtered.
Links
Source
public function script($path, array $options = []) {
$defaults = ['inline' => true];
list($scope, $options) = $this->_options($defaults, $options);
if (is_array($path)) {
foreach ($path as $i => $item) {
$path[$i] = $this->script($item, $scope);
}
return ($scope['inline']) ? join("\n\t", $path) . "\n" : null;
}
$m = __METHOD__;
$params = compact('path', 'options');
$script = Filters::run($this, __FUNCTION__, $params, function($params) use ($m) {
return $this->_render($m, 'script', $params);
});
if ($scope['inline']) {
return $script;
}
if ($this->_context) {
$this->_context->scripts($script);
}
}