So I have some default meta tags on layout.phtml set using
$this->headTitle() and $this->headMeta()->appendName()
and is echoed at layout.phtml's header
My question is: How do I change those default meta tags from the view file such that they are replaced?
I tried using:
$this->headMeta()->appendName() or setName()
Instead of replacing the old default meta tags, it would create an entirely new meta tag. How can I replace them?
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'; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With