When programming a Joomla extension in PHP -- particulary when you need to create a display module -- you often need to get information about about the document being displayed. By instantiating the document object, you can get access to all of the information on everything from the metatags to the template name.
Examining the Joomla Document object
You can examine the properties available through the document object by adding these two lines to your module definition:
$document = &JFactory::getDocument();
print_r($document);
You will get output something like the code shown in Listing 1. So if you want to change the output of a module based on the keywords held in the metatags, you can use code like this:
$document = &JFactory::getDocument();
$metaTags = trim($document->_metaTags['standard']['keywords']);
$keywords = explode(',',$metaTags);
Getting information about the document can help you customize the module output to mirror the type of content displayed in the article.
Listing 1. Example of Joomla Document object information
JDocumentHTML Object
(
[_links] => Array
(
[0] => <link href="/templates/rhuk_milkyway/favicon.ico" rel="shortcut icon" type="image/x-icon"
)
[_custom] => Array
(
)
[template] => rhuk_milkyway
[baseurl] =>
[params] => JRegistry Object
(
[data:protected] => stdClass Object
(
[colorVariation] => blue
[backgroundVariation] => blue
[widthStyle] => fmax
)
)
[_file] => C:\Apache22\htdocs\joomla16\templates\rhuk_milkyway\index.php
[_template:protected] =>
[title] => Sample Sites
[description] => Joomla! - the dynamic portal engine and content management system
[link] =>
[base] => http://localhost_j16/index.php/sample-sites.html
[language] => en-gb
[direction] => ltr
[_generator] => Joomla! 1.6 - Open Source Content Management
[_mdate] =>
[_tab] =>
[_lineEnd] =>
[_charset] => utf-8
[_mime] => text/html
[_namespace] =>
[_profile] =>
[_metaTags] => Array
(
[http-equiv] => Array
(
[content-type] => text/html; charset=utf-8
)
[standard] => Array
(
[robots] => index, follow
[keywords] => joomla, Joomla
[rights] =>
[title] => Sample Sites
[author] => Super User
)
)
[_engine] =>
[_type] => html



Del.ici.ous


