:
$this->headMeta()->appendName('DESCRIPTION', $des);
我的html头中有多个元标记。
<meta name="DESCRIPTION" content="des1" />
<meta name="DESCRIPTION" content="des2" />
我怎样才能阻止它,并在我的html头中有类似的内容:
<meta name="DESCRIPTION" content="des1 des2" />
答案 0 :(得分:2)
而不是
echo $this->headMeta ();
有你的布局
$u = '';
foreach ($this->headMeta ()->getContainer () as $y)
{
if ($y->name == 'description')
{
$u .= $y->content;
}
}
$this->headMeta ()->setName ('description', $u);
echo $this->headMeta ();
答案 1 :(得分:1)
像这样扩展你自己的头视图助手。
$this->headDescription($stringToAttach);
并提供一种方法将值推送到headMeta
$this->headDescription()->pushToHeadMeta();
// internal call like this
$this->view->headMeta('description', $this->getConcatedDescription());
其他选项是使用占位符。
//in view index.phtml
$this->placeholder('description')
->append($desc1);
//in view other.phtml
$this->placeholder('description')
->append($desc2);
// in layout
echo $this->headMeta('description', $this->placeholder('description'));
答案 2 :(得分:1)
您可以使用此功能将您的元素作为数组(我将它放在/application/plugins/common.php中,您可以将它放在您想要的位置):
public function getMetasArray(Zend_View $view){
$metas = array();
foreach ($view->headMeta()->getContainer() as $y)
{
if($y->name!=''){
$metas[$y->name] = $y->content;
}
}
return $metas;
}
并根据需要随时调用:
$metas = Application_Plugin_Common::getMetasArray($this);
echo $metas['description'];