registerMetaTag() public method

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
ファイル: TwitterCard.php プロジェクト: manyoubaby123/imshop
 /**
  * @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
ファイル: Meta.php プロジェクト: nevmerzhitsky/yii2-seomodule
 /**
  * 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
ファイル: WebView.php プロジェクト: tqsq2005/dotplant2
 /**
  * @inheritdoc
  */
 public function registerMetaTag($options, $key = null)
 {
     $this->viewElementsGathener->gather(__FUNCTION__, func_get_args());
     return parent::registerMetaTag($options, $key);
 }
コード例 #5
0
ファイル: Meta.php プロジェクト: manyoubaby123/imshop
 /**
  * @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
ファイル: Page.php プロジェクト: heartshare/yii2-seo-toolbar
 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
ファイル: Post.php プロジェクト: NullRefExcep/yii2-blog
 /**
  * @param View $view
  */
 public function registerMetaTags($view)
 {
     if (!empty($this->meta)) {
         foreach ($this->meta as $metaTag) {
             $view->registerMetaTag($metaTag, $metaTag['name']);
         }
     }
 }
コード例 #8
0
ファイル: Seo.php プロジェクト: Liv1020/cms
 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;
 }