【问题标题】:Zend Framework: Allowing Meta Properties for the HTML5 Doctype (Facebook Open Graph)Zend 框架:允许 HTML5 文档类型的元属性(Facebook Open Graph)
【发布时间】:2013-01-13 05:44:44
【问题描述】:

我在我的 Zend Framework 应用程序中使用HTML5 doctype。如果我使用XHTML1_RDFA 作为我的文档类型,headMeta 视图助手允许我使用appendProperty() 函数。我知道元属性在 HTML5 中无效,但我还是想这样做。如何覆盖该行为以便添加这些元标记?

我在 SO 上找到了这些相关帖子,但他们没有回答这个具体问题:

【问题讨论】:

  • 为什么删除了xhtml1-rdfa 标签?它似乎是一个有效的标签。我应该使用其他标签吗?

标签: html zend-framework facebook-opengraph zend-view rdfa


【解决方案1】:

我扩展了 HeadMeta 视图助手以允许它们。它也在http://validator.w3.org/ 验证。

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;
    }
}

【讨论】:

    猜你喜欢
    • 2013-01-09
    • 2011-12-13
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多