Voici un petit tutorial pour mettre en place le SEO dans Symfony 2 via le bundle SeoBundle.
INSTALLATION
 # installer seo-bundle via Composer
php composer.phar require sonata-project/seo-bundle
 
 La version va être demandée. A l'heure actuelle, c'est la version 1.1.1
 Pour connaitre la dernière version : https://github.com/sonata-project/SonataSeoBundle/tags
 
 # ajouter le bundle SeoBundle au kernel (fichier AppKernel.php)
public function registerbundles()
 {
     return array(
         ...
         new Sonata\SeoBundle\SonataSeoBundle(),
     );
 }
CONFIGURATION
 # pour utiliser SeoBundle, ajouter ceci à votre fichier de configuration app/config/config.yml
sonata_seo: default: sonata.seo.page.default encoding: UTF-8 page: title: Sonata Project metas: name: keywords: foo bar description: The description robots: index, follow property: # Facebook application settings #'fb:app_id': XXXXXX #'fb:admins': admin1, admin2 # Open Graph information # see http://developers.facebook.com/docs/opengraphprotocol/#types or http://ogp.me/ 'og:site_name': Sonata Project Sandbox 'og:description': A demo of the some rich bundles for your Symfony2 projects http-equiv: 'Content-Type': text/html; charset=utf-8 #'X-Ua-Compatible': IE=EmulateIE7 head: 'xmlns': http://www.w3.org/1999/xhtml 'xmlns:og': http://opengraphprotocol.org/schema/ #'xmlns:fb': "http://www.facebook.com/2008/fbml"
 
 
 
 # Si vous souhaitez modifier ces valeurs dans votre controller, voici la démarche à suivre
<?php
 public function testAction()
 {
   $seoPage = $this->container->get('sonata.seo.page');
   $seoPage
     ->setTitle("Editeur")
     ->addMeta('name', 'description', "my new description")
     ->addMeta('property', 'og:title', "my new title")
     ->addMeta('property', 'og:type', 'blog')
     ->addMeta('property', 'og:url',  $this->generateUrl('my_route',array(),true))
     ->addMeta('property', 'og:description', "my new og description")
   ;
  ...
UTILISATION DANS TWIG
 # Titre de la page (attention, ne pas mettre entre les balises <title>
{{ sonata_seo_title() }}
 
 # Metadatas
{{ sonata_seo_metadatas() }}
 
 # Attributs HTML
{{ sonata_seo_html_attributes() }}
 
 
 # EXEMPLE 
<!DOCTYPE html>
 <html {{ sonata_seo_html_attributes() }}>
     <head>
         {{ sonata_seo_title() }}
         {{ sonata_seo_metadatas() }}
     </head>
     ...
Articles en lien
- Tutoriel Symfony2 et OVH : installation et configuration sur serveur mutualisé
- Symfony2 : accéder aux routes dans vos fichiers Javascript
- Symfony2 : traduire vos fichiers Javascript / translate Javascript files
- Symfony 2 : listing des lignes de commandes de base
 
     
     
    
2 commentaire