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
$pathString The name of a JavaScript file, or an array of names.
-
array
$optionsAvailable 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 = array()) {
$defaults = array('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 = $this->_filter(__METHOD__, $params, function($self, $params, $chain) use ($m) {
return $self->invokeMethod('_render', array($m, 'script', $params));
});
if ($scope['inline']) {
return $script;
}
if ($this->_context) {
$this->_context->scripts($script);
}
}