Joomla Jumpstart

  • Increase font size
  • Default font size
  • Decrease font size
Home Professional Joomla! Hacking Joomla! How To Get Joomla 1.6 Document Data within a Module

How To Get Joomla 1.6 Document Data within a Module

E-mail Print PDF
User Rating: / 7
PoorBest 

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
 

Who's Online

We have 28 guests online
beafreelancer #php #job Add Aditional Module Positions to Joomla Template by NovaGarden: My client purchased a Joomla template w... http://bit.ly/ddvG7W
by beafreelancer. Link: twitterfeed
jobboard2bid Joomla : Modify module or create new: We have three sites all using the same mod_ampcontact module but we need it ... http://bit.ly/aziJ6x
by jobboard2bid. Link: twitterfeed
workathomeindia Add Aditional Module Positions to Joomla Template by NovaGarden: My client purchased a Joomla template with only a... http://bit.ly/aSMvpC
by workathomeindia. Link: twitterfeed
cebu_classified Joomla : Modify module or create new by pixeldesignhouse We have three sites all using the same mod_ampcontact module http://bit.ly/9meJGE
by cebu_classified. Link: itweetlive

Google AdSense