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
$pathThe name of a CSS stylesheet in
/app/webroot/css, or an array containing names of CSS stylesheets in that directory. -
array
$optionsAvailable 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, acceptsstylesheetorimport, which respectively correspond tostyle-linkandstyle-importstrings 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 = array()) {
$defaults = array('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;
}
$method = __METHOD__;
$type = $scope['type'];
$params = compact('type', 'path', 'options');
$filter = function($self, $params, $chain) use ($defaults, $method) {
$template = ($params['type'] === 'import') ? 'style-import' : 'style-link';
return $self->invokeMethod('_render', array($method, $template, $params));
};
$style = $this->_filter($method, $params, $filter);
if ($scope['inline']) {
return $style;
}
if ($this->_context) {
$this->_context->styles($style);
}
}