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 = [ 'block' => '{:content}', 'block-end' => '', 'block-start' => '', 'charset' => '', 'image' => '', 'js-block' => '{:content}', 'js-end' => '', 'js-start' => '', 'link' => '{:title}', 'list' => '{:content}', 'list-item' => '{:content}', 'meta' => '', 'meta-link' => '', 'para' => '{:content}

', 'para-start' => '', 'script' => '', 'style' => '{:content}', 'style-import' => '@import url({:url});', 'style-link' => '', 'table-header' => '{:content}', 'table-header-row' => '{:content}', 'table-cell' => '{:content}', 'table-row' => '{:content}', 'tag' => '<{:name}{:options}>{:content}', 'tag-end' => '', 'tag-start' => '<{:name}{:options}>' ]; /** * Data used for custom links. * * @var array */ protected $_metaLinks = [ 'atom' => ['type' => 'application/atom+xml', 'rel' => 'alternate'], 'rss' => ['type' => 'application/rss+xml', 'rel' => 'alternate'], 'icon' => ['type' => 'image/x-icon', 'rel' => 'icon'] ]; /** * List of meta tags to cache and to output. * * @var array * @see lithium\template\helper\Html::meta() */ protected $_metaList = []; /** * Used by output handlers to calculate asset paths in conjunction with the `Media` class. * * @var array * @see lithium\net\http\Media */ public $contentMap = [ 'script' => 'js', 'style' => 'css', 'image' => 'image', '_metaLink' => 'generic' ]; /** * Returns a charset meta-tag for declaring the encoding of the document. * * The terms character set (here: charset) and character encoding (here: * encoding) were historically synonymous. The terms now have related but * distinct meanings. Whenever possible Lithium tries to use precise * terminology. Since HTML uses the term `charset` we expose this method * under the exact same name. This caters to the expectation towards a HTML * helper. However the rest of the framework will use the term `encoding` * when talking about character encoding. * * It is suggested that uppercase letters should be used when specifying * the encoding. HTML specs don't require it to be uppercase and sites in * the wild most often use the lowercase variant. On the other hand must * XML parsers (those may not be relevant in this context anyway) not * support lowercase encodings. This and the fact that IANA lists only * encodings with uppercase characters led to the above suggestion. * * @see lithium\net\http\Response::$encoding * @link http://www.iana.org/assignments/character-sets * @param string $encoding The character encoding to be used in the meta tag. * Defaults to the encoding of the `Response` object attached to the * current context. The default encoding of that object is `UTF-8`. * The string given here is not manipulated in any way, so that * values are rendered literally. Also see above note about casing. * @return string A meta tag containing the specified encoding (literally). */ public function charset($encoding = null) { if ($response = $this->_context->response()) { $encoding = $encoding ?: $response->encoding; } return $this->_render(__METHOD__, 'charset', compact('encoding')); } /** * Creates an HTML link (``) or a document meta-link (``). * * If `$url` starts with `'http://'` or `'https://'`, this is treated as an external link. * Otherwise, it is treated as a path to controller/action and parsed using * the `Router::match()` method (where `Router` is the routing class dependency specified by * the rendering context, i.e. `lithium\template\view\Renderer::$_classes`). * * If `$url` is empty, `$title` is used in its place. * * @param string $title The content to be wrapped by an `` tag, * or the `title` attribute of a meta-link ``. * @param mixed $url Can be a string representing a URL relative to the base of your Lithium * application, an external URL (starts with `'http://'` or `'https://'`), an * anchor name starting with `'#'` (i.e. `'#top'`), or an array defining a set * of request parameters that should be matched against a route in `Router`. * @param array $options The available options are: * - `'escape'` _boolean_: Whether or not the title content should be escaped. * Defaults to `true`. * - `'type'` _string_: The meta-link type, which is looked up in * `Html::$_metaLinks`. By default it accepts `atom`, `rss` and `icon`. If a `type` * is specified, this method will render a document meta-link (``), * instead of an HTML link (``). * - any other options specified are rendered as HTML attributes of the element. * @return string Returns an `` or `` element. */ public function link($title, $url = null, array $options = []) { $defaults = ['escape' => true, 'type' => null]; list($scope, $options) = $this->_options($defaults, $options); if (isset($scope['type']) && $type = $scope['type']) { $options += compact('title'); return $this->_metaLink($type, $url, $options); } $url = $url === null ? $title : $url; return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $scope); } /** * Returns a JavaScript include tag (`