大侠实验室 / yii2-taggedview
扩展,用于设置标准的HTML元标签,除了Opengraph和Twitter定义的标签之外,有助于提升网站SEO
1.0.3
2021-08-25 13:47 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-08-25 20:35:43 UTC
README
扩展,用于设置标准的HTML元标签,除了Opengraph和TwitterCard定义的标签之外,有助于提升网站SEO
安装
安装此扩展的首选方法是通过 composer。
运行以下命令
php composer.phar require --prefer-dist daxslab/yii2-taggedview "*"
或者在您的 composer.json
文件的 require 部分添加以下内容
"daxslab/yii2-taggedview": "*"
配置
将视图组件配置到您的应用程序的主配置文件中
'components' => [ //... 'view' => [ 'class' => 'daxslab\taggedview\View', //configure some default values that will be shared by all the pages of the website //if they are not overwritten by the page itself 'image' => 'http://domain.com/images/default-image.jpg', ], //... ]
默认值
组件将尝试默认设置一些属性
$this->site_name = Yii::$app->name; $this->url = Yii::$app->request->baseUrl; $this->locale = Yii::$app->language;
您可以在每个页面或组件配置中覆盖这些标签的内容。
使用方法
一旦配置了扩展,只需在您的视图中使用即可
<?php $this->title = 'page title'; $this->description = 'page description'; $this->keywords = ['keywords', 'for', 'this', 'page']; $this->image = 'http://domain.com/images/page-image.jpg'; ?>
由 Daxslab 制作。