How to dynamically set open graph meta tags in zend for facebook sharing

981 views Asked by At

I want to set open graph meta tags dynamically so it can be done either from controller or from view. I have tried many things which I got during searching but din't succeed. Following are the solutions which I have already tried:

I have written the following lines in onBootstrap method of Module.php

    $doctypeHelper = new Doctype();
    $doctypeHelper->setDoctype('XHTML1_RDFA');

and then in index.phtml of view I tried to set description meta tag by writing the following lines of code.

    <script>
    <?php echo $this->doctype('XHTML1_RDFA'); ?>
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:og="http://opengraphprotocol.org/schema/">
    <head>
    <meta property="og:description" content="musician" />
    </script>

I have also tried this solution, I had written following lines of code in my controller.

    $renderer = $this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');  
    $renderer->headMeta()->appendName('og:description', 'pimcore is great'); 

Is there any way by which I can set open graph meta tags dynamically ? I have to set these meta tags "og:url", "og:title" , "og:image" ,"og:description".

1

There are 1 answers

0
Saeven On

The HeadMeta helper http://framework.zend.com/manual/current/en/modules/zend.view.helpers.head-meta.html

Will definitely work. Take a look at the last example on that page:

$this->doctype(Zend\View\Helper\Doctype::XHTML1_RDFA);
$this->headMeta()->setProperty('og:title', 'my article title');
$this->headMeta()->setProperty('og:type', 'article');