2017 © Pedro Peláez
 

symfony-bundle seo-bundle

Symfony SEO bundle : create title and meta html tag with the request attributes

image

ayrel/seo-bundle

Symfony SEO bundle : create title and meta html tag with the request attributes

  • Friday, January 27, 2017
  • by ayrel
  • Repository
  • 4 Watchers
  • 2 Stars
  • 87 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

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)

SensioLabsInsight Build Status Coverage Status, (*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)

Configure Your first Route

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)
    {
        /*.....*/
    }

    /*....*/
}

Configure all your routes in one file

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}}'

Configure default meta

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)

The Versions

27/01 2017

dev-master

9999999-dev https://github.com/laurentosp/AyrelSeoBundle

Symfony SEO bundle : create title and meta html tag with the request attributes

  Sources   Download

MIT

The Development Requires

by Laurent Rossillol
by Olivier Dupont

title seo open-graph description twitter-card