2017 © Pedro PelĂĄez
 

symfony-bundle seo-bundle

Handle SEO metatags config & rendering

image

norsys/seo-bundle

Handle SEO metatags config & rendering

  • Tuesday, July 17, 2018
  • by mageekguy
  • Repository
  • 9 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Seo Bundle

Package version Total Downloads Build Status Scrutinizer Coverage Scrutinizer Code Quality License, (*1)

SensioLabsInsight, (*2)

This project is a bundle to handle SEO meta/link tags configuration & rendering, (*3)

Installation

Step 1: Add the repository & download the Bundle

Open a command console, enter your project directory and execute the following commands:, (*4)

# download the latest stable version of this bundle:
$ composer require norsys/seo-bundle

This command requires you to have composer installed globally, as explained in the installation chapter of the Composer documentation., (*5)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*6)

` and `` tags verbatims can be translated using symfony translation system, using keys.

_app/config/config.yml_
```yaml
# ...

# Config options for NorsysSeoBundle
norsys_seo:
    
    # i18n config (if no "translation" key present in config, the default behavior is to have translations disabled)
    translation: 
        # implicitly tell the bundle to use SF translation system
        enabled: true
        # Name of the translation domain to be used for verbatims (MANDATORY)
        domain: seo
    
    # Configuration for titles
    title:
        # This is the fallback value when no title defined for the requested route (MANDATORY)
        default: defaults.title

        # Other routes title overrides 
        pages:
            faq: faq.title
            # ...

    # Configuration for meta tags
    metas:
        # This are the fallback values, used for meta-tags when no config exist for the requested route
        defaults:
            - { charset: UTF-8 }
            - { name: description, content: defaults.description }

        pages:
            # Each route can override and/or implement its own meta-tags
            faq:
                - { name: description, content: faq.description }
            # It's possible to remove the default description with set null (~ in Yaml)
            blog:
                - { name: description, content: ~}

    # Configuration for link tags
    links:
        pages:
            home:
                - { rel: shortcut icon, href: img/favicon.ico, type: image/x-icon }

# ...
```

Translation keys are stored in a proper domain, which name is defined by the value of `domain` under `norsys_seo` config section.

The file as to be named `<domain>`.`<locale>`.`<format>` and reside in `src/AppBundle/Resource/translations/` directory. 
_Format can be one of the following: `xml`,`yml`,`php`,`ini`,`xliff` or any other custom format you implemented (see [Symfony Documentation](http://symfony.com/doc/current/translation.html) for more information)_

_src/AppBundle/Resource/translations/seo.fr.yml_
```yaml
# Translations for SEO meta tags
defaults:
    title:       Acme Demo WebSite
    description: Acme Demo Website is a website demonstrating the full potential of Acme 
faq:
    title:       Acme Demo FAQ
    description: Acme's most Frequently Asked Questions, the hottest subjects!
# ...
```

Step 4: Usage
-------------

This bundle comes up with a `Twig` extension which exposes 3 functions for tag rendering:
- `seo_render_metas(route)`
- `seo_render_links(route)`
- `seo_render_title(route)`

Example:

```twig
{# Render the <title> tag, based on SEO config #}
{{ seo_render_title(app.request.route) }}

{# Render all meta tags #}
{{ seo_render_metas(app.request.route) }}


{# Render all link tags #}
{{ seo_render_links(app.request.route) }}

```

Rewrite
-------

This bundle provide a system to rewrite urls from all requests

To configure rewrite system :

```yaml
norsys_seo:
    rewrite: 
        remove_trailing_slash: true # enable remove trailing slash in urls, default false
```

Sitemap
-------

This bundle can expose `/sitemap.xml` url for you. Just import `routing.yml` in your routing configuration :

```yaml
_norsys_seo:
    resource: "@NorsysSeoBundle/Resources/config/routing.yml"
    prefix:   /
```

Now, you can expose each route to sitemap. Sample :

```yaml
home:
    path: /
    methods: [GET]
    defaults:
        _controller: 'AppBundle\Action\Home'
        template: 'AppBundle::home.html.twig'
    options:
        sitemap: true

```

Sitemap generated:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>/</loc>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
</urlset>

Credits

Developped with :heart: by Norsys, (*7)

License

This project is licensed under the MIT license., (*8)

The Versions