2011-03-15 206 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'];