views:

1186

answers:

1

Hi,
I'm using Zend Framework 1.8. I have a problem with headMeta() duplicating my meta keywords.

In my layout.phtml, I have
<?php echo $this->headMeta(); ?>

I have a Custom Controller_Plugin_ViewSetup (extending Zend_Controller_Plugin_Abstract) that has the following code in it, in the dispatchLoopStartup() function:
$view->headMeta()->setHttpEquiv('Content-Type', 'text/html;charset=utf-8'); $view->headMeta()->setName('keywords', 'global,generic,keywords,');

Finally, in my view scripts, I have the following:
$this->headMeta()->appendName('keywords', 'view,specific,keywords');

I was expecting that in my HTML source code, I would see:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="keywords" content="global,generic,keywords,view,specific,keywords" />

However, I actually see this:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="keywords" content="global,generic,keywords," />
<meta name="keywords" content="view,specific,keywords" />

In other words, the meta keywords aren't concatenating together as they should. What am I doing wrong?

Cheers,
Matt

+3  A: 

That's because the append method doesn't append more key words to the list already defined. The append method will append the next tag to the tags already defined. Similarly, if you chose prepend, this would add your new tag before the one you defined in your plugin.

I think, the best thing to do, would be to remove the keywords place holder from the plugin and store your default keywords in your config object and insert these into your view at the same time that you add your additional keywords.

Kieran Hall
Thanks for the info - guess I didn't read the documentation well enough! I'll do as you suggested
fistameeny