Wallogit.com
2017 © Pedro Peláez
A simple symfony2 bundle to add custom meta to your layout(s)
First, grab the RuianSeoBundle :, (*3)
Add the following lines to your deps file and then run php bin/vendors
install:, (*4)
[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:, (*5)
``` php <?php // app/autoload.php $loader->registerNamespaces(array( // ... 'Ruian' => DIR.'/../vendor/bundles', // ... ));, (*6)
### Step 3) Register the bundle To start using the bundle, register it in your Kernel: ``` php ## Use it You can set your title and metas with the DIC (all entries are optional) ``` yaml #/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 ``` php //... 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 ## PHP ``` php renderTitle() ?> <?php echo $view['ruian.seo.page']->renderMetas() ?> </head> <body> <!-- ... --> </body> </html>
twig
<html>
<head>
{{ ruian_seo_title() }}
{{ ruian_seo_metas() }}
</head>
<body>
<!-- ... -->
</body>
</html>, (*7)
..., (*9)