Cake\View\Helper\HtmlHelper::meta PHP Метод

meta() публичный Метод

Create a meta tag that is output inline: $this->Html->meta('icon', 'favicon.ico'); Append the meta tag to custom view block "meta": $this->Html->meta('description', 'A great page', ['block' => true]); Append the meta tag to custom view block: $this->Html->meta('description', 'A great page', ['block' => 'metaTags']); Create a custom meta tag: $this->Html->meta(['property' => 'og:site_name', 'content' => 'CakePHP']); ### Options - block` - Set to true to append output to view block "meta" or provide custom block name.
public meta ( string | array $type, string | array | null $content = null, array $options = [] ) : string
$type string | array The title of the external resource
$content string | array | null The address of the external resource or string for content attribute
$options array Other attributes for the generated tag. If the type attribute is html, rss, atom, or icon, the mime-type is returned.
Результат string A completed `` element.
    public function meta($type, $content = null, array $options = [])
    {
        $options += ['block' => null];
        if (!is_array($type)) {
            $types = ['rss' => ['type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $content], 'atom' => ['type' => 'application/atom+xml', 'title' => $type, 'link' => $content], 'icon' => ['type' => 'image/x-icon', 'rel' => 'icon', 'link' => $content], 'keywords' => ['name' => 'keywords', 'content' => $content], 'description' => ['name' => 'description', 'content' => $content], 'robots' => ['name' => 'robots', 'content' => $content], 'viewport' => ['name' => 'viewport', 'content' => $content], 'canonical' => ['rel' => 'canonical', 'link' => $content], 'next' => ['rel' => 'next', 'link' => $content], 'prev' => ['rel' => 'prev', 'link' => $content], 'first' => ['rel' => 'first', 'link' => $content], 'last' => ['rel' => 'last', 'link' => $content]];
            if ($type === 'icon' && $content === null) {
                $types['icon']['link'] = 'favicon.ico';
            }
            if (isset($types[$type])) {
                $type = $types[$type];
            } elseif (!isset($options['type']) && $content !== null) {
                if (is_array($content) && isset($content['_ext'])) {
                    $type = $types[$content['_ext']];
                } else {
                    $type = ['name' => $type, 'content' => $content];
                }
            } elseif (isset($options['type'], $types[$options['type']])) {
                $type = $types[$options['type']];
                unset($options['type']);
            } else {
                $type = [];
            }
        }
        $options += $type;
        $out = null;
        if (isset($options['link'])) {
            $options['link'] = $this->Url->assetUrl($options['link']);
            if (isset($options['rel']) && $options['rel'] === 'icon') {
                $out = $this->formatTemplate('metalink', ['url' => $options['link'], 'attrs' => $this->templater()->formatAttributes($options, ['block', 'link'])]);
                $options['rel'] = 'shortcut icon';
            }
            $out .= $this->formatTemplate('metalink', ['url' => $options['link'], 'attrs' => $this->templater()->formatAttributes($options, ['block', 'link'])]);
        } else {
            $out = $this->formatTemplate('meta', ['attrs' => $this->templater()->formatAttributes($options, ['block', 'type'])]);
        }
        if (empty($options['block'])) {
            return $out;
        }
        if ($options['block'] === true) {
            $options['block'] = __FUNCTION__;
        }
        $this->_View->append($options['block'], $out);
    }

Usage Example

Пример #1
0
 /**
  * Creates a link to an external resource and handles basic meta tags.
  *
  * @param array|string $type
  * @param null $content
  * @param array $options
  * @return string
  */
 public function meta($type, $content = null, array $options = [])
 {
     return parent::meta($type, $content, $options) . $this->Document->eol;
 }
All Usage Examples Of Cake\View\Helper\HtmlHelper::meta