Download the PHP package aldaflux/seo-bundle without Composer
On this page you can find all versions of the php package aldaflux/seo-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package seo-bundle
AldafluxSeoBundle
This bundle provides a simple and flexible API to manage search engine optimization (SEO) tags in your application. Its main goal is to make it simple for you to manage the most common meta, open graph and twitter card tags and to let you configure less common ones with ease.
Installation
Install the bundle with the command:
composer require aldaflux/seo-bundle
Register the bundle in your AppKernel:
Configuration
These configuration values are the defaults used to render your tags. See the next section to learn how to override them dynamically.
There are four sections in the config:
general
: The global configuration. Its values are shared among the other as defaults.basic
: A set of the most common SEO tags.og
: A set of open graph tags based on http://ogp.me/.twitter
: A set of twitter card tags based on https://dev.twitter.com/cards/types
See "Configuration reference" to get the whole configuration.
In your config.yml
:
In your view:
NOTE: _You can provide a generator name to the aldaflux_seo()
twig method to render it specifically.
For example, to render the basic
seo generator, you can use aldaflux_seo('basic')
._
The result:
NOTE: By default, the SEO generators aren't loaded if you don't require them in the config. However, if you want to use the associated generators without configuring any default values (or configuring only the general ones), you can use this notation:
Setting values dynamically
You can get the '[basic|twitter|og]
as a service to set or override any values.
Each value of the configuration can be overrided using a setter of the following form:
$this->get('aldaflux_seo.provider.generator')->get('
[basic|twitter|og] ')->set
[config field name] (
[value] )
For example, if you want to change title
and robots
from basic
, you can do this:
Setting values from a resource
You can configure your own model classes to let the seo generators do all the work thanks to the fromResource() method. Multiple interfaces are available to help the method guess which setters to call to fill the tags.
This is an exemple for the basic
generator:
In your resource:
In your controller:
In your view:
The result:
There are three main interfaces, one for each generator:
BasicSeoInterface
forbasic
OgSeoInterface
forog
TwitterSeoInterface
fortwitter
These interfaces extends simpler interfaces which you can inplement instead or additionnally.
For example, if you only have a meta description on your resource, you can implement DescriptionSeoInterface
only to provide a description alone.
This is the list of the different interfaces and what they extends:
TitleSeoInterface | DescriptionSeoInterface | KeywordsSeoInterface | ImageSeoInterface | |
---|---|---|---|---|
BasicSeoInterface | X | X | X | |
OgSeoInterface | X | X | X | |
TwitterSeoInterface | X | X | X |
Advanced usage
If the built-in generators don't suit your needs, LeogoutSeoBundle provides a way to create your own SEO generators. First, you have to create a class that extends the AbstractSeoGenerator class:
Then, register it as a service and add it a aldaflux_seo.generator
tag and a custom alias.
Don't forget the @aldaflux_seo.builder
dependency:
That's it, now you can use it alongside the others:
In your controller:
In your view:
Result:
Configuration reference
Contributing
If you want to contribute (thank you!) to this bundle, here are some guidelines:
- Please respect the Symfony guidelines
- Test everything! Please add tests cases to the tests/ directory when:
- You fix a bug that wasn't covered before
- You add a new feature
- You see code that works but isn't covered by any tests (there is a special place in heaven for you)
Todo
- Packagist
Thanks
Many thanks to the ARCANEDEV/SEO-Helper who authorized me to take some ideas from their library and to KnpMenuBundle which inspired me for the Providers APIs.