我想动态设置开放图形元标记,以便可以从控制器或视图中完成。我尝试了很多我在搜索过程中得到的东西,但没有成功。以下是我已经尝试过的解决方案:
我在 Module.php 的 onBootstrap 方法中写了以下几行
$doctypeHelper = new Doctype();
$doctypeHelper->setDoctype('XHTML1_RDFA');
然后在视图的 index.phtml 中,我尝试通过编写以下代码行来设置描述元标记。
<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>
我也尝试过这个解决方案,我在控制器中编写了以下代码行。
$renderer = $this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
$renderer->headMeta()->appendName('og:description', 'pimcore is great');
有什么方法可以动态设置开放图元标记?我必须设置这些元标记“og:url”、“og:title”、“og:image”、“og:description”。