Question

I am using the HTML5 doctype in my Zend Framework application. If I use XHTML1_RDFA as my doctype, the headMeta view helper allows me to use the appendProperty() function. I know that meta properties are not valid in HTML5, but I want to do it anyway. How do I override the behavior so that I can add these meta tags?

I've found these related posts on SO, but they don't answer this specific question:

Was it helpful?

Solution

I extended the HeadMeta view helper to allow them. It validates at http://validator.w3.org/ too.

class My_View_Helper_HeadMeta extends Zend_View_Helper_HeadMeta
{
    /**
     * Determine if item is valid
     *
     * @param  mixed $item
     * @return boolean
     */
    protected function _isValid($item)
    {
        if ((!$item instanceof stdClass)
            || !isset($item->type)
            || !isset($item->modifiers))
        {
            return false;
        }

        if (!isset($item->content)
        && (! $this->view->doctype()->isHtml5()
        || (! $this->view->doctype()->isHtml5() && $item->type !== 'charset'))) {
            return false;
        }

        // <meta property= ... /> is only supported with doctype RDFa
        if (!$this->view->doctype()->isRdfa()
            && !$this->view->doctype()->isHtml5()
            && $item->type === 'property') {
            return false;
        }

        return true;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top