diff --git a/docs/reference/usage.rst b/docs/reference/usage.rst index 4af498da..9f1a8702 100644 --- a/docs/reference/usage.rst +++ b/docs/reference/usage.rst @@ -51,6 +51,10 @@ However, it is possible to alter these values at runtime: ->addMeta('property', 'og:description', $post->getAbstract()) ; +.. note:: + + If you need a shortcut to inject the seo page into any class, you could use the + ``Sonata\SeoBundle\Seo\SeoAwareTrait``. These values can be used inside a twig template. diff --git a/src/Seo/SeoAwareTrait.php b/src/Seo/SeoAwareTrait.php new file mode 100644 index 00000000..db37ea74 --- /dev/null +++ b/src/Seo/SeoAwareTrait.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\SeoBundle\Seo; + +trait SeoAwareTrait +{ + /** + * @var SeoPageInterface|null + * + * @required + */ + protected $seoPage; + + public function setSeoPage(SeoPageInterface $seoPage = null) + { + $this->seoPage = $seoPage; + } +}