Multivalued meta tags in html head

in Zend FW, when I add a description meta tag in a loop using a helper:

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

In my html head I got some meta tags.

 <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" /> 
0
source share
3 answers

Extend your own helper in the form of a header, called this way.

 $this->headDescription($stringToAttach); 

and suggest a method for moving values ​​in headMeta p>

 $this->headDescription()->pushToHeadMeta(); // internal call like this $this->view->headMeta('description', $this->getConcatedDescription()); 

Another 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')); 
+1
source

Established

 echo $this->headMeta (); 

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 (); 
+2
source

You can use this function to get the 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 call it when you want and as you want:

 $metas = Application_Plugin_Common::getMetasArray($this); echo $metas['description']; 
+1
source

Source: https://habr.com/ru/post/1286417/


All Articles