First, grab the RuianSeoBundle :
Add the following lines to your deps
file and then run php bin/vendors install
:
[RuianSeoBundle]
git=git://github.com/ruian/RuianSeoBundle.git
target=bundles/Ruian/SeoBundle
Add the following two namespace entries to the registerNamespaces
call
in your autoloader:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Ruian' => __DIR__.'/../vendor/bundles',
// ...
));
To start using the bundle, register it in your Kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Ruian\SeoBundle\RuianSeoBundle(),
);
// ...
)
You can set your title and metas with the DIC (all entries are optional)
#/app/config/config.yml
ruian_seo:
title_prefix: '[FR] '
title: "My website is awesome"
title_suffix: ' - jgalenski.com'
metas:
keywords: "Cool, stuff"
description: "a cool description"
...: ...
metas_http_equiv:
charset: "utf8"
...: ...
Or with your controller
//... DefaultController.php
public function indexAction()
{
// ...
$this->get('ruian.seo.page')->setTitle("My website title");
$this->get('ruian.seo.page')->setMeta('keywords', "Cool, stuff");
$this->get('ruian.seo.page')->setMeta('description', "a cool description");
$this->get('ruian.seo.page')->setMetaHttpEquiv('charset', 'utf8');
// ...
)
And now see the result in your layout/view
<html>
<head>
<?php echo $view['ruian.seo.page']->renderTitle() ?>
<?php echo $view['ruian.seo.page']->renderMetas() ?>
</head>
<body>
<!-- ... -->
</body>
</html>
<html>
<head>
{{ ruian_seo_title() }}
{{ ruian_seo_metas() }}
</head>
<body>
<!-- ... -->
</body>
</html>
...