Enable javascript for live chat

Knowledge Base Overview

Set property meta tag

Share on Tumblr

When you use the Open Graph protocol [og] you need meta tags in your HTML document's head. If you want to use a Facebook Like (share) button you will have to use Open Graph in your document.

ZF view helper headMeta

In Zend Framework you can use the headMeta view helper and setProperty() to add the name and content value. Most likely you will see error "Invalid value passed to set; please use setMeta()".

You may wonder why because that will not work, i.e. the message to use setMeta is wrong. There is a simple reason for this and an easy solution.

DocType RDFa

The simple reason is that Open Graph is part of or relies on another protocol by the short name RDFa. From W3C RDFa specification we have the follow short introduction:

RDFa is intended to solve the problem of marking up machine-readable data in HTML documents. RDFa provides a set of HTML attributes to augment visual data with machine-readable hints. Using RDFa, authors may turn their existing human-visible text and links into machine-readable data without repeating content.

RDFa stand for Resource Description Framework-attributes by the way. For more information about RDF see Wikipedia.

Set new doctype

Unfortunately the metaHead view helper uses an _isValid() method that checks the doctype set for your view. If it is not RDFa the method simply returns false and triggers the rather meaningless error message telling you "please use setMeta()" which is not the correct solution for the error.

So, the easily solution is to add a new doctype with the Zend Framework before you use setProperty().

$this->view->doctype('XHTML1_RDFA'); // controller
$this->doctype('XHTML1_RDFA'); // view

Now you should be able to add all the propery values.

blog comments powered by Disqus