Header image

Symfony Finland
Random things on PHP, Symfony and web development

Facebook sharing metadata for eZ Platform with Open Graph Bundle

Facebook sharing uses the Open Graph protocol to markup web documents to contain metadata. Because the eZ Platform is built using the Full Stack Symfony framework, developers can leverage existing Symfony Bundles.

There is an existing Open Graph Bundle for the symfony framework that can be used together with eZ Platform to add Open Graph Metadata to your projects. The OpenGraphProtocolBundle can contain default values:

#OGP Bundle
open_graph_protocol:
    libraries:
        base:
            class: Beyerz\OpenGraphProtocolBundle\Libraries\Base
            default_values:
                site_name: {{ default value for website name }}
                type: {{ default value for website type }}
                title: {{ default value for any page title }}
                url: {{ default value for any canonical url (acts as a fall back for bad pages) }}
                image: {{ default image for your site }}
                description: {{ default generic page description for your site }}
        facebook:
            class: Beyerz\OpenGraphProtocolBundle\Libraries\Facebook
            default_values: { app_id: {{ Your apps facebook id }} }

in addition you can choose to override values in your controllers to fully customize output for your content repository and the structure it represents:

$ogp = $this->get('beyerz.ogp.open_graph');
$base = $ogp->get('base');
$base->addMeta('title', "My dynamic title");
$base->addMeta('url', $request->getSchemeAndHttpHost().$request->getRequestUri());
$base->addMeta('description', "My dynamic description");

Using existing bundles helps code reuse and leads to faster implementation. So instead of rolling yoru own Open Graph Integration for eZ Platform, consider using this Bundle:


Written by Jani Tarvainen on Wednesday November 9, 2016
Permalink -

Leave a comment

comments powered by Disqus

« A GraphQL enabled CaaS (Content as a Service) platform -