registerMetaTag() публичный метод

For example, a description meta tag can be added like the following: php $view->registerMetaTag([ 'name' => 'description', 'content' => 'This website is about funny raccoons.' ]); will result in the meta tag .
public registerMetaTag ( array $options, string $key = null )
$options array the HTML attributes for the meta tag.
$key string the key that identifies the meta tag. If two meta tags are registered with the same key, the latter will overwrite the former. If this is null, the new meta tag will be appended to the existing ones.
Пример #1
1
 /**
  * @param View $view
  */
 public function applyTo(View $view)
 {
     $attributes = $this->getAttributes(null, ['id', 'meta_id']);
     foreach ($attributes as $name => $value) {
         $view->registerMetaTag(['property' => 'twitter:' . $name, 'content' => $value]);
     }
 }
Пример #2
1
 /**
  * Register global meta tags like verifications and so on
  *
  * @param View $view
  */
 protected static function registerGlobalMetaTags($view)
 {
     $globalMetaTags = Yii::$app->cache->get('__globalMetaTags');
     if ($globalMetaTags === false) {
         $globalMetaTags = GlobalMetaTag::find()->andWhere(['active' => 1])->asArray()->all();
         Yii::$app->cache->set('__globalMetaTags', $globalMetaTags, 3600 * 24);
     }
     foreach ($globalMetaTags as $globalTag) {
         $view->registerMetaTag(['name' => $globalTag['name'], 'content' => $globalTag['content']], $globalTag['name']);
     }
 }
Пример #3
0
 /**
  * Set other meta tags
  * For example, OpenGraph tags
  *
  * @param array $data
  * @return $this
  */
 protected function _setTags($data)
 {
     $tags = ArrayHelper::merge($this->_defaultMetaData['tags'], $data['tags']);
     if (!empty($tags)) {
         foreach ($tags as $tagName => $tagProp) {
             if (!empty($tagProp) && is_string($tagProp)) {
                 $tagProp = $this->_substituteVars($tagProp);
             }
             $this->_view->registerMetaTag(['property' => $tagName, 'content' => $tagProp]);
         }
     }
     return $this;
 }
Пример #4
0
 /**
  * @inheritdoc
  */
 public function registerMetaTag($options, $key = null)
 {
     $this->viewElementsGathener->gather(__FUNCTION__, func_get_args());
     return parent::registerMetaTag($options, $key);
 }
Пример #5
0
 /**
  * @param View $view
  */
 public function applyTo(View $view)
 {
     $view->params['metaTitle'] = $this->meta_title ? $this->meta_title : $view->title;
     if ($this->meta_description) {
         $view->registerMetaTag(['name' => 'description', 'content' => $this->meta_description], 'description');
     }
     if ($this->meta_robots) {
         $view->registerMetaTag(['name' => 'robots', 'content' => $this->meta_robots], 'robots');
     }
     if ($this->custom_meta) {
         $view->params['customMeta'] = isset($view->params['customMeta']) ? $view->params['customMeta'] .= "\n" . $this->custom_meta : "\n" . $this->custom_meta;
     }
     //        if ($this->openGraph !== null)
     //            $this->openGraph->applyTo($view);
 }
Пример #6
0
 public function registerMeta(View $view)
 {
     $view->title = $this->renderAttribute($this->title);
     $view->registerMetaTag(['name' => 'description', 'content' => $this->renderAttribute($this->description)]);
     $view->registerMetaTag(['name' => 'keywords', 'content' => $this->renderAttribute($this->keywords)]);
     foreach ($this->getOgTags() as $tag) {
         $view->registerMetaTag(['property' => $tag['property'], 'content' => $this->renderAttribute($tag['content'])]);
     }
 }
Пример #7
0
 /**
  * @param View $view
  */
 public function registerMetaTags($view)
 {
     if (!empty($this->meta)) {
         foreach ($this->meta as $metaTag) {
             $view->registerMetaTag($metaTag, $metaTag['name']);
         }
     }
 }
Пример #8
0
 public function generateBeforeOutputPage(\yii\web\View $view)
 {
     $content = ob_get_contents();
     if (!isset($view->metaTags['keywords'])) {
         $view->registerMetaTag(["name" => 'keywords', "content" => $this->keywords($content)], 'keywords');
     }
     \Yii::$app->response->content = $content;
 }