rudak / seo_bundle
dev-master
2017-04-07 17:03 UTC
Requires
- php: ^5.5.9 || ^7.0
- symfony/templating: ^2.7 || ^3.0
- twig/twig: ^1.28 || ^2.0
This package is auto-updated.
Last update: 2024-09-11 15:10:11 UTC
README
轻松管理您的元标签
安装
composer require rudak/seo_bundle
启用Bundle
#AppKernel.php
$bundles = [
//...
new Rudak\SeoBundle\RudakSeoBundle(),
];
配置
一些参数是必需的,一些是可选的
#config.yml
rudak_seo:
title: title you want
description: Description you want
author: RudaK
og_title: My Website - Blog #optional
og_description: My website is blue #optional
og_image: relative/path/article.jpg #optional
og_type: article #optional
og_locale: fr_FR #optional
fb_app_id: abcdefghijklmnopqrstuvwxyz0123456789 #optional
使用
元对象会自动使用config.yml中的默认值进行配置。您只需在视图中调用twig函数来打印填充的元标签。
基本示例
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ seo_title() }}
{{ seo_description() }}
{{ seo_author() }}
</head>
将变为
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>your default title</title>
<meta name="description" content="your default description">
<meta name="author" content="your default author">
</head>
在您的控制器中更新值
public function blogAction($id)
{
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository('AppBundle:Blog')->find($id);
$metaValues = [
'title' => $article->getName(),
'description' => 'what an article ! it\'s so good',
'author' => $article->getAuthor(),
'og_type' => 'article',
];
$metaBuilder = $this->get('rudak_seo.builder');
$metaBuilder->updateMetaObject($metaValues);
return $this->render('default/article.html.twig', [
'article' => $article,
]);
}
值将在模板中更新。这就完了 ;)