stevecohenfr / ezseobundle
Write your SEO for eZ Platform easily
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:ezplatform-bundle
Requires
- php: ^5.6 || ^7.1
- ezsystems/ezpublish-kernel: ^6.13@dev || ^7.5@dev
This package is auto-updated.
Last update: 2025-04-05 23:54:36 UTC
README
EzSeoBundle
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require stevecohenfr/ezseobundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
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:
// app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new SteveCohenFR\EzSeoBundle\SteveCohenFREzSeoBundle(), ); // ... } // ... }
Step 3: Create your own provider
app/config.yml
steve_cohen_fr_ez_seo: providers: article: class: ACME\ACMEBundle\SEO\Providers\ArticleProvider
Provider example:
<?php namespace ACME\ACMEBundle\SEO\Providers; use SteveCohenFR\EzSeoBundle\SEO\Providers\AbstractProvider; class ArticleProvider extends AbstractProvider { /** * @override */ function getMetaTitle() { /* Get first defined attribute */ $metaTitle = $this->array_find([ $this->getContent()->getFieldValue('meta_title'), $this->getContent()->getFieldValue('title') ], function($elem) { return $elem != null && $elem != ''; }); return $metaTitle; } /** * @override */ function getMetaDescription() { /* Get first defined attribute */ $metaDesc = $this->array_find([ $this->getContent()->getFieldValue('meta_description'), $this->getContent()->getFieldValue('intro')->xml->textContent, $this->getContent()->getFieldValue('catcher')->xml->textContent ], function($elem) { return $elem != null && $elem != ''; }); return $metaDesc; } /** * Return the first item that match the user provided callback */ private function array_find($xs, $f) { foreach ($xs as $x) { if (call_user_func($f, $x) === true) return $x; } return null; } }
Step 4: Include SEO in your pagelayout
In your pagelayout.html.twig add this line between tags
<!-- SEO --> {{ render( controller( 'SteveCohenFREzSeoBundle:Seo:showMetaSeo', { content: content, prefix: "", suffix: " | ACME" } )) }}
- content (required): Your current content (eZ\Publish\API\Repository\Values\Content)
- prefix: A prefix for your Meta Title
- suffix: A suffix for your Meta Title
Availables variables
You can access useful variables in your SEO Provider, like eZ Platform Repository, Container and Content
/** * Get the current content * @var \eZ\Publish\API\Repository\Values\Content\Content $content */ $content = $this->getContent(); /** * Get eZ Platform Repository * @var \eZ\Publish\Core\SignalSlot\Repository $repository */ $repository = $this->getRepository(); /** * Get symfony Container * @var \Symfony\Component\DependencyInjection\Container $container */ $container = $this->getContainer(); /** * Get a service * @var ACME\ACMEBundle\Services\MyService */ $myService = $container->get('my.service'); /** * Get a parameter from ParametersBag * @var string $myParam */ $myParam = $container->getParameter('my.parameter');