How to change meta tags in zend framework layout How to change meta tags in zend framework layout php php

How to change meta tags in zend framework layout


I just tested this, and setName() should work:

<?php $this->headMeta()->setName('keywords', 'test'); ?><?php $this->headMeta()->setName('keywords', 'test'); ?>

Results in:

<meta name="keywords" content="another test" >  

While:

<?php $this->headMeta()->setName('keywords', 'test'); ?><?php $this->headMeta()->appendName('keywords', 'another test'); ?>

Results in:

<meta name="keywords" content="test" > <meta name="keywords" content="another test" > 


I would recommend setting a view variable for the keywords. For example, in your bootstrap.php you could define a default keywords as follows:

protected function _initSetDefaultKeywords() {     $view = $this->bootstrap('view')->getResource('view');             $view->keywords = 'default keywords';}

In layout.phtml you would have then:

<?php echo $this->headMeta()->appendName('keywords', $this->keywords); ?>

Finally, in your views (or actions) you could change the meta keywords simply by changing the keywords view variable:

// in an action$this->view->keywords = 'new kewords';//or in a view<?php $this->keywords = 'new kewords'; ?>


Here's what worked for me. In the layout file you have to make sure that the meta tags are echoed. It's empty at the stage but you will be marking where the meta tags will be outputted. This only disadvantage with this method would be that there doesn't seem to be a way to have a default meta tag so you will have to add the meta tag in each view file.

In the layout file

<?php echo $this->headMeta(); ?>

In the view .phtml file

$this->headMeta("test description text", "description");