AyrelSeoBundle
With this bundle you can configure html meta tag and title tag in a config file : /app/config/seo.yml or just by adding an seo annotation., (*1)
You can write meta tags with Twig patterns. The available variables are those in the Request attributes., (*2)
, (*3)
Install
Step 1 : Download
use composer..., (*4)
composer require ayrel/seo-bundle dev-master
Step 2 : Enable The Bundle
add the Bundle to your application kernel, (*5)
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Ayrel\SeoBundle\AyrelSeoBundle(),
// ...
);
}
it's done... you can enjoy!!!, (*6)
use Ayrel\SeoBundle\Annotation\SeoAnnotation as Seo;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
* @Seo({
* "title": "my Website | {{_route}}",
* "description": "this is the route {{_route}} of my website"
* })
*/
public function indexAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('default/index.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
]);
}
/*....*/
}
Use with The ParamConverter Component
The ParamConverter Component register the params attributes of your Controller in the Request attributes., (*7)
With this Bundle you can access these Object to write amazing templates., (*8)
use Ayrel\SeoBundle\Annotation\SeoAnnotation as Seo;
use AppBundle\Entity\Product;
class DefaultController extends Controller
{
/**
* @Route("/product/{id}", name="product")
* @Seo({
* "title": "{{product.title}} : {{product.price}} €",
* "description": "{{product.desc}}"
* })
*/
public function productAction(Product $product)
{
/*.....*/
}
/*....*/
}
You can set your metaTag Templates by annotation. But you can also write a yml file to configure all you routes., (*9)
Just create a app/config/seo.yml file, (*10)
and configure your templates :, (*11)
homepage:
title: 'my beautifull title'
description: 'this is a description'
og_title: 'you can share this'
og_description: 'this is a so interesting webpage....'
product:
title: '{{product.title}} : {{product.price}} €'
description: '{{product.desc}}'
you can add default value to the meta., (*12)
Just write you're app/config/config.yml file, (*13)
ayrel_seo:
default:
title: 'my webisite | {_route}'
if you want to use the default meta value, configure the route meta with a NULL value., (*14)
homepage:
title: ~
Resources
Twig Strategy, (*15)