html`, which will auto-load this helper into the rendering context. For examples of how * to use this helper, see the documentation for a specific method. For a list of the * template strings this helper uses, see the `$_strings` property. */ class Html extends \lithium\template\Helper { /** * String templates used by this helper. * * @var array */ protected $_strings = array( 'block' => '
` along with your other styles. * - `'type'` _string_: By default, accepts `stylesheet` or `import`, which * respectively correspond to `style-link` and `style-import` strings templates * defined in `Html::$_strings`. * - any other options specified are rendered as HTML attributes of the element. * @return string CSS or tag, depending on the type of link. * @filter This method can be filtered. */ 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); } } /** * Creates a tag for the `
` section of your document.
*
* If there is a rendering context, then it also pushes the resulting tag to it.
*
* The `$options` must match the named parameters from `$_strings` for the
* given `$tag`.
*
* @param string $tag the name of a key in `$_strings`
* @param array $options the options required by `$_strings[$tag]`
* @return mixed a string if successful, otherwise `null`
* @filter This method can be filtered.
*/
public function head($tag, array $options) {
if (!isset($this->_strings[$tag])) {
return null;
}
$method = __METHOD__;
$filter = function($self, $options, $chain) use ($method, $tag) {
return $self->invokeMethod('_render', array($method, $tag, $options));
};
$head = $this->_filter($method, $options, $filter);
if ($this->_context) {
$this->_context->head($head);
}
return $head;
}
/**
* Creates a formatted `` element.
*
* @param string $path Path to the image file. 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 the images directory, usually
* `app/webroot/img/`. If the name starts with `'http://'`, this is treated
* as an external url used as the `src` attribute.
* @param array $options Array of HTML attributes.
* @return string Returns a formatted `
` tag.
* @filter This method can be filtered.
*/
public function image($path, array $options = array()) {
$defaults = array('alt' => '');
$options += $defaults;
$path = is_array($path) ? $this->_context->url($path) : $path;
$params = compact('path', 'options');
$method = __METHOD__;
return $this->_filter($method, $params, function($self, $params, $chain) use ($method) {
return $self->invokeMethod('_render', array($method, 'image', $params));
});
}
/**
* Creates a link to an external resource.
*
* @param string $type The title of the external resource
* @param mixed $url The address of the external resource or string for content attribute
* @param array $options Other attributes for the generated tag. If the type attribute
* is 'html', 'rss', 'atom', or 'icon', the mime-type is returned.
* @return string
*/
protected function _metaLink($type, $url = null, array $options = array()) {
$options += isset($this->_metaLinks[$type]) ? $this->_metaLinks[$type] : array();
if ($type === 'icon') {
$url = $url ?: 'favicon.ico';
$standard = $this->_render(__METHOD__, 'meta-link', compact('url', 'options'), array(
'handlers' => array('url' => 'path')
));
$options['rel'] = 'shortcut icon';
$ieFix = $this->_render(__METHOD__, 'meta-link', compact('url', 'options'), array(
'handlers' => array('url' => 'path')
));
return "{$standard}\n\t{$ieFix}";
}
return $this->_render(__METHOD__, 'meta-link', compact('url', 'options'), array(
'handlers' => array()
));
}
}
?>