Friday, January 27, 2012

How to set page title in joomla 1.5

Accessing Your Page Title from Your Template

There are 2 objects in Joomla! 1.5 that are extremely powerful and extremely useful for doing some advanced tricks in your template. The first object is JFactory, which is basically the gateway for accessing just about anything in the Joomla! API, and the second is JDocument, which gives you access to your document's properties. 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; 

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); 
 

No comments: