in Zend FW when I add description meta tag in loop using helper:
$this->headMeta()->appendName('DESCRIPTION', $des);
i got multi meta tags in my html head.
<meta name="DESCRIPTION" content="des1" />
<meta name="DESCRIPTION" content="des2" />
how can i prevent it and have something like below in my html head:
<meta name="DESCRIPTION" content="des1 des2" />
Extend you own head view helper callable like this.
$this->headDescription($stringToAttach);
and offer a method to push the values to headMeta
$this->headDescription()->pushToHeadMeta();
// internal call like this
$this->view->headMeta('description', $this->getConcatedDescription());
Other option is to use placeholders.
//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'));
Insted of
echo $this->headMeta ();
have in your layout
$u = '';
foreach ($this->headMeta ()->getContainer () as $y)
{
if ($y->name == 'description')
{
$u .= $y->content;
}
}
$this->headMeta ()->setName ('description', $u);
echo $this->headMeta ();
You can use this function to get your metas as an array (I put it in /application/plugins/common.php you can put it where you want) :
public function getMetasArray(Zend_View $view){
$metas = array();
foreach ($view->headMeta()->getContainer() as $y)
{
if($y->name!=''){
$metas[$y->name] = $y->content;
}
}
return $metas;
}
and to call it when you want and as you want :
$metas = Application_Plugin_Common::getMetasArray($this);
echo $metas['description'];