2011-03-15 68 views
0

在Zend的FW当我使用辅助环路添加描述meta标签:多描述meta标签

$this->headMeta()->appendName('DESCRIPTION', $des);

我在我的HTML头多meta标签。


<meta name="DESCRIPTION" content="des1" /> 
<meta name="DESCRIPTION" content="des2" /> 

如何防止它,在我的HTML头类似如下:


<meta name="DESCRIPTION" content="des1 des2" /> 
+0

创建$ DES使用一个循环,然后将其添加到标签 – criticus 2011-03-15 17:22:16

+0

没有这还不够,因为我想添加到描述的任何地方,我需要的,也许在其他视图或插件 – 2011-03-15 17:32:14

回答

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

echo $this->headMeta(); 

insted的在你的布局

$u = ''; 
foreach ($this->headMeta()->getContainer() as $y) 
{ 
    if ($y->name == 'description') 
    { 
     $u .= $y->content; 
    } 
} 
$this->headMeta()->setName ('description', $u); 

echo $this->headMeta(); 
1

您可以使用此功能,让您的METAS作为数组(我把它放在/应用/插件/共同.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'];