lithium\template\helper\Html::style()
Creates a <link />
element for CSS stylesheets or a <style />
tag. 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 stylesheets path, usually webroot/css
.
Parameters
-
mixed
$path
The name of a CSS stylesheet in
webroot/css
, or an array containing names of CSS stylesheets in that directory. -
array
$options
Available options are:
'inline'
boolean: Whether or not the<style />
element should be output inline. When set tofalse
, thestyles()
handler prints out the styles, and other specified styles to be included in the layout. Defaults totrue
. This is useful when page-specific styles are created inline in the page, and you'd like to place them in the<head />
along with your other styles.'type'
string: By default, acceptsstylesheet
orimport
, which respectively correspond tostyle-link
andstyle-import
strings templates defined inHtml::$_strings
.- any other options specified are rendered as HTML attributes of the element.
Returns
stringCSS or tag, depending on the type of link.
Filter
This method can be filtered.
Source
public function style($path, array $options = []) {
$defaults = ['type' => 'stylesheet', 'inline' => true];
list($scope, $options) = $this->_options($defaults, $options);
if (is_array($path)) {
foreach ($path as $i => $item) {
$path[$i] = $this->style($item, $scope);
}
return ($scope['inline']) ? join("\n\t", $path) . "\n" : null;
}
$m = __METHOD__;
$type = $scope['type'];
$params = compact('type', 'path', 'options');
$style = Filters::run($this, __FUNCTION__, $params, function($params) use ($m) {
$template = ($params['type'] === 'import') ? 'style-import' : 'style-link';
return $this->_render($m, $template, $params);
});
if ($scope['inline']) {
return $style;
}
if ($this->_context) {
$this->_context->styles($style);
}
}