Help with CHtml::metaTags


I'm trying to insert dynamic meta tags using CHtml::metaTags method, but it is inserted above the <head> tag rather than within the tag.  As well, the html is outputted in reverse to conventional formats. 

<meta content="this is a test" name="description"/>


<meta name="description" content="this is a test" />

I’m just using a statement like

echo CHtml::metaTag(‘this is a test’,‘description’)
at the beginning of an action. 

Here is the output I get…

<meta content=“this is a test” name=“description”/><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns="" xml:lang="en" lang="en">


      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      <meta name="language" content="en" />

Am I using this incorrectly?  Should it not automatically stuff the meta tag within the head tag and the proper format?



I think you should use this function inside the View not inside the controller.

Try to put in layout.


Between <head> and </head> tags use this:

echo CHtml::metaTag('this is a test','description')

Thanks for your reply, but I don't see how this could be updated dynamically if it is inserted in a layout file.  What if I want the content to be different for each view that is tied to one layout? 


I do this way:

inside the controller in a action method:

class AppController extends CController


	public $metaDescricao = null;


And in the layout file:

<meta name="description" content="<?php echo $this->metaDescricao ?>" />

Get it?

Yes thank you, I understand this method.  It was outlined in this thread http://www.yiiframew…html#msg10327.