Your document is usually defined as the HTML output from Joomla!, but it could also be a PDF, XML/RSS, or raw output/text. In this case, we are only concerned with the HTML output.
To access your page title, simply add the following code to the top of your template "index.php" file:
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();
?>
That's it. That's all there is to it. Pretty simple, huh? Now, to display your page title within your template, you simply add the following code anywhere in your template "index.php" file that you wish to display the page title:
echo $mytitle; ?>
That's all there is to it. Pretty easy.
Modifying Your HTML Title
The next thing we want to do is modify your html title. We will be using the JDocument object that we just accessed. Using this code, you can set the html title of your page:
$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename');
$mydoc->setTitle($mytitle.' - '.$sitename);
Notice that I used JFactory again to get a copy of the Joomla! configuration, which I then used to get the value of the site name (config.sitename). Then, I used "$mydoc" from the earlier step to set the html title.
Note that this code sets the html title to "Page Title - Site Name". If you want to set it to "Site Name - Page Title", you need to change the setTitle parameter to "$sitename.' - '.$mytitle". In reality, you can set the html title to anything you want, but I personally think "Page Title - Site Name" makes the most sense.
Putting it All Together
Using the following code, you are simultaneously getting dynamic access to your page title and setting the value of your html title:
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();
$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename');
$mydoc->setTitle($mytitle.' - '.$sitename);
?>
Resource : http://www.howtojoomla.net/content/view/86/2/



